Direct Selection: picked direction handles move together

A click on a path's direction handle picks it, a Shift-click adds it to
the picked handles or takes it away, and Escape lets them go. Picked
handles show ringed. Dragging one of two or more picked handles moves
all of them, on one path or several, by the same offset in one undo
step. A Shift-press on a handle reshapes only once the pointer has moved
3 pixels, so a Shift-click leaves the handle where it is.

The new command path.moveHandles does the move: an anchor with one
handle listed places it as path.setHandle does, an anchor with both
listed moves both and becomes a corner, and independent (Alt during the
drag) makes every listed handle's anchor a corner.

Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo committed 2026-11-28 04:58:12 -08:00
1 parent 3d88485fa6
commit 41a6005414
7 files changed
+537 -26

No files matched your search

+85
View File
@@ -54,6 +54,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_doc,
set_handle
),
cmd!(
"path.moveHandles",
"Move Direction Handles",
[],
None,
"{handles: [{id, subpath?, anchor, which: \"in\"|\"out\"}, ...], dx, dy, independent?: bool} move several direction handles by (dx, dy) as one undo step; an anchor with one handle listed moves it as path.setHandle does (a smooth anchor turns its other handle in line at its own length), and an anchor with both handles listed moves both and becomes a corner; independent (default false) makes every listed handle's anchor a corner and leaves its other handle; a handle listed twice moves once; an empty list, a missing or unknown path, subpath or anchor, or a which other than \"in\" or \"out\" is refused",
has_doc,
move_handles
),
cmd!(
"path.moveAnchor",
"Move Anchor Point",
@@ -584,6 +593,82 @@ fn set_handle(s: &mut Session, p: &Value) -> Result<Value> {
ok()
}
/// `path.moveHandles`: the listed direction handles move by `(dx, dy)` together, as one undo step.
/// Each anchor with one listed handle places it as `path.setHandle` does; an anchor with both
/// listed moves both and becomes a corner. A move by nothing, with no anchor to make a corner,
/// records no undo step.
fn move_handles(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "path.moveHandles";
let list = match p.get("handles") {
None | Some(Value::Null) => return Err(bad(C, "missing handles")),
Some(v) => v.as_array().ok_or_else(|| bad(C, "`handles` must be an array"))?,
};
if list.is_empty() {
return Err(bad(C, "`handles` is empty"));
}
let d = Vec2::new(f64_req(p, "dx", C)?, f64_req(p, "dy", C)?);
if !(d.x.abs() < 1e9 && d.y.abs() < 1e9) {
return Err(bad(C, "dx and dy must be finite"));
}
let independent = switch_or(p, "independent", false, C)?;
if s.script_running() {
return Err(EngineError::Busy);
}
// Each anchor with the sides of it listed: (incoming, outgoing).
let mut anchors: BTreeMap<(NodeId, usize, usize), (bool, bool)> = BTreeMap::new();
let doc = &s.doc()?.doc;
for (i, h) in list.iter().enumerate() {
if !h.is_object() {
return Err(bad(C, format!("handles[{i}] must be an object")));
}
let id = object_param(h, "id", C)?.ok_or_else(|| bad(C, format!("handles[{i}]: missing id")))?;
let si = usize_opt(h, "subpath", C)?.unwrap_or(0);
let ai = index_opt(h, "anchor", C)?.ok_or_else(|| bad(C, format!("handles[{i}]: missing anchor")))?;
let out = match str_param(h, "which") {
Some("out") => true,
Some("in") => false,
_ => return Err(bad(C, format!("handles[{i}]: `which` must be \"in\" or \"out\""))),
};
let n = doc.node(id).ok_or(EngineError::NoNode(id))?;
let NodeKind::Path { path, .. } = &n.kind else { return Err(bad(C, format!("handles[{i}]: object {id} is not a path"))) };
if path.subpaths.get(si).and_then(|sp| sp.anchors.get(ai)).is_none() {
return Err(bad(C, format!("handles[{i}]: object {id} has no anchor {ai} in subpath {si}")));
}
let e = anchors.entry((id, si, ai)).or_default();
if out { e.1 = true } else { e.0 = true }
}
// A move by nothing changes only the kind of anchors that become corners: those with both
// handles listed, or every listed one with `independent`.
if d == Vec2::ZERO {
let corners = anchors.iter().any(|(&(id, si, ai), &(inn, out))| {
(independent || (inn && out))
&& doc
.node(id)
.and_then(|n| n.path_data())
.and_then(|pd| pd.subpaths.get(si)?.anchors.get(ai))
.is_some_and(|a| a.kind != AnchorKind::Corner)
});
if !corners {
return ok();
}
}
s.edit("Reshape", |doc, _| {
for (&(id, si, ai), &(inn, out)) in &anchors {
let a = path_mut(doc, id)?.anchor_mut(si, ai).ok_or_else(|| EngineError::Other("no such anchor".into()))?;
if inn && out {
a.kind = AnchorKind::Corner;
a.h_in += d;
a.h_out += d;
} else {
let h = if out { a.h_out } else { a.h_in };
a.set_handle(out, h + d, independent);
}
}
Ok(())
})?;
ok()
}
/// `path.setHandle` with `link` (the Anchor Point tool's Alt-drag on a handle): the handle goes to
/// (x, y) and the anchor becomes smooth, its other handle turned in line at its own length. A
/// retracted other handle is pulled out to the moved handle's length when a segment leaves the
@@ -473,6 +473,7 @@ pub(super) const ALLOWED: &[&str] = &[
"path.mirrorCut",
"path.moveAnchor",
"path.moveAnchors",
"path.moveHandles",
"path.quickPen",
"path.quickPenLength",
"path.rectCut",
+1
View File
@@ -35,6 +35,7 @@ mod ruler_guide_perf;
mod ruler_origin;
mod script_host_vs_scriptcheck;
mod selection_commands;
mod several_handles;
mod stroke_visibility;
mod text_stroke_scale;
mod three_d_light_color;
+193
View File
@@ -0,0 +1,193 @@
//! Direct Selection picks several direction handles and drags them together (`path.moveHandles`).
use serde_json::{Value, json};
use vectorcraft_doc::NodeId;
use vectorcraft_engine::{Session, ViewInfo};
use vectorcraft_geom::{Anchor, AnchorKind, Point};
use vectorcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey};
fn view() -> ViewInfo {
ViewInfo {
smart_guides: false,
guides: false,
snap_to_point: false,
snap_to_grid: false,
snap_to_pixel: false,
snap_to_glyph: false,
corner_widgets: false,
show_bbox: false,
..ViewInfo::default()
}
}
/// A path selected whole with Direct Selection chosen: anchor 1 is smooth, its incoming handle at
/// (50, 100) and its outgoing one at (180, 100); anchor 2's incoming handle is at (300, 140).
fn session() -> (Session, NodeId) {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 900, "height": 700})).unwrap();
for (key, value) in [("constrainAngle", json!(0)), ("showHandlesMultipleAnchors", json!(true))] {
s.execute("prefs.set", &json!({"key": key, "value": value})).unwrap();
}
let id = s
.execute(
"path.create",
&json!({"anchors": [
{"x": 20, "y": 220},
{"x": 100, "y": 100, "in": [50, 100], "out": [180, 100]},
{"x": 320, "y": 220, "in": [300, 140]}
]}),
)
.unwrap();
let id = NodeId(id["id"].as_u64().unwrap());
s.select_tool("directSelection", view()).unwrap();
(s, id)
}
fn anchor(s: &Session, id: NodeId, i: usize) -> Anchor {
s.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().subpaths[0].anchors[i]
}
fn pointer(s: &mut Session, kind: PointerKind, at: Point, mods: Mods) {
s.pointer(&PointerEvent::new(kind, at.x, at.y).with_mods(mods), view()).unwrap();
}
fn click(s: &mut Session, at: Point, mods: Mods) {
pointer(s, PointerKind::Down, at, mods);
pointer(s, PointerKind::Up, at, mods);
}
fn drag(s: &mut Session, from: Point, to: Point, mods: Mods) {
pointer(s, PointerKind::Down, from, mods);
pointer(s, PointerKind::Drag, Point::new((from.x + to.x) / 2.0, (from.y + to.y) / 2.0), mods);
pointer(s, PointerKind::Drag, to, mods);
pointer(s, PointerKind::Up, to, mods);
}
fn shift() -> Mods {
Mods { shift: true, ..Mods::default() }
}
fn near(actual: Point, expected: Point) {
assert!(actual.distance(expected) < 1e-6, "point {actual:?}, expected {expected:?}");
}
fn undo_len(s: &Session) -> usize {
s.doc().unwrap().history.undo.len()
}
fn document(s: &Session) -> Value {
json!(s.doc().unwrap().doc)
}
/// A click picks a handle and a Shift-click adds another without moving it; a drag of either then
/// moves both by the same offset, and a smooth anchor turns its other handle in line, as one undo
/// step that Undo takes back whole.
#[test]
fn a_drag_of_one_of_two_picked_handles_moves_both_in_one_undo_step() {
let (mut s, id) = session();
let before = document(&s);
click(&mut s, Point::new(180.0, 100.0), Mods::default());
// A Shift-click with a small slip of the pointer picks the handle and leaves it where it is.
pointer(&mut s, PointerKind::Down, Point::new(300.0, 140.0), shift());
pointer(&mut s, PointerKind::Drag, Point::new(301.0, 140.0), shift());
pointer(&mut s, PointerKind::Up, Point::new(301.0, 140.0), shift());
near(anchor(&s, id, 2).h_in, Point::new(300.0, 140.0));
let undo = undo_len(&s);
drag(&mut s, Point::new(180.0, 100.0), Point::new(180.0, 130.0), Mods::default());
let a = anchor(&s, id, 1);
near(a.h_out, Point::new(180.0, 130.0));
assert_eq!(a.kind, AnchorKind::Smooth);
// The incoming handle keeps its length (50) and turns in line with the moved one.
let dir = (a.p - a.h_out) / (a.p - a.h_out).hypot();
near(a.h_in, a.p + dir * 50.0);
near(anchor(&s, id, 2).h_in, Point::new(300.0, 170.0));
assert_eq!(undo_len(&s), undo + 1, "one undo step");
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(document(&s), before);
}
/// The picked handles stay picked after their drag, and a second drag of the other one moves both
/// again.
#[test]
fn picked_handles_stay_picked_after_they_are_dragged() {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
drag(&mut s, Point::new(180.0, 100.0), Point::new(180.0, 130.0), Mods::default());
drag(&mut s, Point::new(300.0, 170.0), Point::new(310.0, 170.0), Mods::default());
near(anchor(&s, id, 1).h_out, Point::new(190.0, 130.0));
near(anchor(&s, id, 2).h_in, Point::new(310.0, 170.0));
}
/// A Shift-click on a picked handle takes it away, and Escape lets every picked handle go: a drag
/// then moves only the handle pressed.
#[test]
fn shift_click_and_escape_let_picked_handles_go() {
for escape in [false, true] {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
if escape {
s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap();
} else {
click(&mut s, Point::new(180.0, 100.0), shift());
}
drag(&mut s, Point::new(300.0, 140.0), Point::new(300.0, 170.0), Mods::default());
near(anchor(&s, id, 2).h_in, Point::new(300.0, 170.0));
near(anchor(&s, id, 1).h_out, Point::new(180.0, 100.0));
}
}
/// Both handles of a smooth anchor picked move together and the anchor becomes a corner; with Alt,
/// each picked handle's anchor becomes a corner and keeps its other handle.
#[test]
fn both_handles_of_an_anchor_or_alt_make_a_corner() {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(50.0, 100.0), shift());
drag(&mut s, Point::new(180.0, 100.0), Point::new(180.0, 120.0), Mods::default());
let a = anchor(&s, id, 1);
near(a.h_out, Point::new(180.0, 120.0));
near(a.h_in, Point::new(50.0, 120.0));
assert_eq!(a.kind, AnchorKind::Corner);
let (mut s, id) = session();
let alt = Mods { alt: true, ..Mods::default() };
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
drag(&mut s, Point::new(180.0, 100.0), Point::new(180.0, 130.0), alt);
let a = anchor(&s, id, 1);
near(a.h_out, Point::new(180.0, 130.0));
near(a.h_in, Point::new(50.0, 100.0));
assert_eq!(a.kind, AnchorKind::Corner);
near(anchor(&s, id, 2).h_in, Point::new(300.0, 170.0));
}
/// `path.moveHandles` refuses a list it cannot act on, moves a handle listed twice once, and
/// records no undo step for a move by nothing.
#[test]
fn move_handles_checks_its_params() {
let (mut s, id) = session();
let h = |anchor: u64, which: &str| json!({"id": id.0, "anchor": anchor, "which": which});
let before = document(&s);
let undo = undo_len(&s);
for (params, message) in [
(json!({"dx": 1, "dy": 1}), "missing handles"),
(json!({"handles": [], "dx": 1, "dy": 1}), "`handles` is empty"),
(json!({"handles": {}, "dx": 1, "dy": 1}), "`handles` must be an array"),
(json!({"handles": [h(1, "out")], "dy": 1}), "missing number `dx`"),
(json!({"handles": [h(1, "out")], "dx": 1, "dy": 1, "independent": "yes"}), "`independent` must be true or false"),
(json!({"handles": [{"id": id.0, "anchor": 1}], "dx": 1, "dy": 1}), "`which` must be \"in\" or \"out\""),
(json!({"handles": [h(1, "out"), h(9, "in")], "dx": 1, "dy": 1}), "has no anchor 9 in subpath 0"),
(json!({"handles": [{"anchor": 1, "which": "in"}], "dx": 1, "dy": 1}), "missing id"),
] {
let err = s.execute("path.moveHandles", &params).unwrap_err().to_string();
assert!(err.contains(message), "{params}: {err}");
}
s.execute("path.moveHandles", &json!({"handles": [h(1, "out")], "dx": 0, "dy": 0})).unwrap();
assert_eq!(document(&s), before);
assert_eq!(undo_len(&s), undo, "no undo step for a refused call or a move by nothing");
s.execute("path.moveHandles", &json!({"handles": [h(2, "in"), h(2, "in")], "dx": 5, "dy": 0})).unwrap();
near(anchor(&s, id, 2).h_in, Point::new(305.0, 140.0));
assert_eq!(undo_len(&s), undo + 1);
}
+243 -26
View File
@@ -7,7 +7,9 @@
//! on a path selected whole adds its group, and each further Alt-click adds the next group up, as
//! Group Selection's clicks do), drag a direction handle to
//! reshape (Shift keeps it at 45° steps round its anchor, Alt moves it alone; smart guides snap
//! it), marquee to select anchors (Shift-drag toggles them: the selected ones inside are
//! it), click a direction handle to pick it (Shift-click adds or removes it, Escape lets the picked
//! handles go) and drag one of several picked handles to move them all by the same offset in one
//! undo step, marquee to select anchors (Shift-drag toggles them: the selected ones inside are
//! deselected, the others selected; with Alt held at the press, as Group Selection for the drag,
//! it selects every object it touches, whole), drag a corner widget of any path (a star, a pen
//! path) to round its corners
@@ -87,9 +89,41 @@ struct HandleDrag {
translated: bool,
}
/// A direction handle of a path: (subpath, anchor, outgoing).
type HandleRef = (usize, usize, bool);
/// The picked direction handles, each path with its handles.
type PickedHandles = BTreeMap<NodeId, BTreeSet<HandleRef>>;
/// What [`DirectSelectionTool::notify`] hears after a press picked direction handles or a drag
/// moved them: the picks stay at the revision that follows.
const HANDLES_PICKED: &str = "handles";
/// A press on a direction handle's end of an ordinary path, kept until its release: a release
/// without a drag picks the handle ([`DirectSelectionTool::handles`]).
#[derive(Clone, Debug)]
struct HandlePress {
handle: (NodeId, HandleRef),
at: Point,
shift: bool,
/// The pointer went past the drag distance from `at`.
moved: bool,
/// The picked handles when the press began.
picked: PickedHandles,
}
#[derive(Clone, Debug)]
enum State {
Idle,
/// Dragging one of several picked direction handles: every picked handle moves by the same
/// offset (`path.moveHandles`). `from` is where the pressed handle was, the point that snaps.
Handles {
handle: (NodeId, HandleRef),
from: Point,
start: Point,
items: Vec<(NodeId, HandleRef)>,
began: bool,
},
/// Dragging the selected anchors, which move alike: `grab` is where the anchor pressed on (or
/// the point of a straight segment nearest the pointer pressed on it, `segment`) was, the
/// point that snaps. With Snap to Grid or Snap to Pixel, a segment's drag snaps its anchors
@@ -268,6 +302,14 @@ pub struct DirectSelectionTool {
/// The already selected frame anchor the press landed on without Shift: a click (no drag)
/// selects it alone, as a drag moves every selected frame anchor with it.
frame_click: Option<(NodeId, AnchorRef)>,
/// Direction handles of ordinary paths picked by a click (Shift-click adds one or takes it
/// away): they show ringed, and a drag of one of two or more moves them all. They stay picked
/// while the document and its selection are at `handles_revision`, the revision after they were
/// picked or the tool last moved them, and while their handles show.
handles: PickedHandles,
handles_revision: (u64, u64),
/// The press on a handle in progress.
handle_press: Option<HandlePress>,
/// Where the pointer last hovered: the type on a path bracket under it draws thicker.
bracket_hover: Option<Point>,
/// The Cmd/Ctrl press that lent this tool for one gesture (`lentByCmd`) is still
@@ -317,11 +359,37 @@ impl DirectSelectionTool {
frame: BTreeMap::new(),
frame_revision: (0, 0),
frame_click: None,
handles: BTreeMap::new(),
handles_revision: (0, 0),
handle_press: None,
bracket_hover: None,
lent_cmd: false,
}
}
/// The picked direction handles that still apply, each path with its handles: those of
/// ordinary paths whose handles show ([`handle_anchors`]), while nothing else changed the
/// document or the selection since they were picked (a drag of them changes it as it goes).
fn picked_handles(&self, cx: &ToolContext) -> PickedHandles {
let dragging = matches!(self.state, State::Handles { began: true, .. });
if self.group || self.handles.is_empty() || (!dragging && cx.revision != self.handles_revision) {
return BTreeMap::new();
}
let mut v = PickedHandles::new();
for (id, si, ai, a) in handle_anchors(cx) {
let Some(set) = self.handles.get(&id) else { continue };
if !cx.doc.node(id).is_some_and(|n| matches!(n.kind, NodeKind::Path { .. })) {
continue;
}
for (out, has) in [(false, a.has_in()), (true, a.has_out())] {
if has && set.contains(&(si, ai, out)) {
v.entry(id).or_default().insert((si, ai, out));
}
}
}
v
}
/// The selected frame anchors that still apply, each object with its anchors. They apply while
/// nothing else changed the document or the selection since they were picked (a drag of them
/// changes it as it goes), and only while the selection holds nothing else: every selected
@@ -997,6 +1065,11 @@ impl Tool for DirectSelectionTool {
if key == ToolKey::Escape && self.guide.busy() {
return self.guide.cancel();
}
// Escape with direction handles picked lets them go.
if key == ToolKey::Escape && matches!(self.state, State::Idle) && !self.picked_handles(cx).is_empty() {
self.handles.clear();
return vec![];
}
if key == ToolKey::Escape && matches!(self.state, State::Idle) && cx.selection.key_anchor.is_some() {
return vec![Action::Exec("select.key".into(), json!({}))];
}
@@ -1005,26 +1078,36 @@ impl Tool for DirectSelectionTool {
}
// A mesh point drag ends here too; the `Action::Cancel` below undoes it.
self.mesh.cancel();
// The frame anchors a cancelled drag held stay selected.
// The frame anchors or handles a cancelled drag held stay selected.
let frame = matches!(self.state, State::TypeArea { .. }) && !self.frame.is_empty();
let handles = matches!(self.state, State::Handles { .. });
self.state = State::Idle;
self.guides.clear();
(self.anchor_snap, self.copy_snap, self.move_snap) = (None, None, None);
self.last_location = None;
(self.click, self.click_segment, self.click_group, self.frame_click) = (None, None, None, None);
if frame { vec![Action::Cancel, Action::Notify(FRAME_PICKED.into())] } else { vec![Action::Cancel] }
self.handle_press = None;
match (frame, handles) {
(true, _) => vec![Action::Cancel, Action::Notify(FRAME_PICKED.into())],
(_, true) => vec![Action::Cancel, Action::Notify(HANDLES_PICKED.into())],
_ => vec![Action::Cancel],
}
}
fn claims_key(&self, cx: &ToolContext, key: ToolKey) -> bool {
(matches!(self.state, State::Corner(_)) && matches!(key, ToolKey::Up | ToolKey::Down))
|| self.claims_letter(key)
|| self.mesh_nudge(cx, key, Mods::default()).is_some()
|| self.frame_nudge(cx, key, Mods::default()).is_some()
|| (key == ToolKey::Escape && (cx.selection.key_anchor.is_some() || !matches!(self.state, State::Idle)))
|| (key == ToolKey::Escape
&& (cx.selection.key_anchor.is_some() || !matches!(self.state, State::Idle) || !self.picked_handles(cx).is_empty()))
}
fn notify(&mut self, cx: &ToolContext, what: &str) {
if what == FRAME_PICKED {
self.frame_revision = cx.revision;
}
if what == HANDLES_PICKED {
self.handles_revision = cx.revision;
}
}
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
self.bracket_hover = (ev.kind == PointerKind::Move).then_some(ev.pos);
@@ -1044,6 +1127,10 @@ impl Tool for DirectSelectionTool {
vec![]
}
(PointerKind::Down, _) => {
// A press anywhere but on a handle lets the picked handles go.
let picks = self.picked_handles(cx);
self.handles.clear();
self.handle_press = None;
self.click = None;
self.click_segment = None;
self.click_group = None;
@@ -1075,26 +1162,8 @@ impl Tool for DirectSelectionTool {
if !ev.mods.shift {
self.mesh.unfocus();
}
if let Some((id, si, ai, out)) = hit_handle(cx, p, point) {
let drag = cx.doc.node(id).and_then(|n| match &n.kind {
NodeKind::Path { path, .. } => {
let a = path.subpaths.get(si)?.anchors.get(ai)?;
Some(HandleDrag {
at: a.p,
last: p,
handle: if out { a.h_out } else { a.h_in },
offset: Vec2::ZERO,
space: false,
independent: false,
symmetric: false,
translated: false,
})
}
_ => None,
});
self.state = State::Handle { id, si, ai, out, drag };
self.handle_snap = HandleSnap::default();
return vec![Action::Begin("Reshape".into())];
if let Some(handle) = hit_handle(cx, p, point) {
return self.press_handle(cx, ev, p, handle, picks);
}
if let Some((id, anchor, from)) = hit_spine_point(cx, p, point) {
// The points of this spine picked before: Shift-click adds the point or takes
@@ -1187,6 +1256,10 @@ impl Tool for DirectSelectionTool {
self.state = State::TypeArea { items, start, began: true };
out
}
(PointerKind::Drag, State::Handles { handle, from, start, items, began }) => {
self.drag_handles(cx, ev, p, handle, (from, start, began), items)
}
(PointerKind::Up, State::Handles { handle, began, .. }) => self.release_handles(handle, began),
(PointerKind::Drag, State::Handle { id, si, ai, out, drag: Some(drag) }) => self.drag_handle(cx, ev, p, (id, si, ai, out), drag),
(PointerKind::Drag, State::Handle { id, si, ai, out, drag: None }) => {
let (q, guides) = self.handle_snap.snap(cx, (id, si, ai), p, ev.mods.shift);
@@ -1275,7 +1348,9 @@ impl Tool for DirectSelectionTool {
(PointerKind::Up, State::Handle { .. } | State::SpineHandle { .. }) => {
self.state = State::Idle;
self.guides.clear();
vec![Action::Commit]
let mut out = vec![Action::Commit];
out.extend(self.pick_clicked_handle());
out
}
(PointerKind::Up, State::Marquee { start, toggle, enclosed, whole, .. }) => self.release_marquee(cx, p, (start, toggle, enclosed, whole)),
_ => vec![],
@@ -1296,10 +1371,11 @@ impl Tool for DirectSelectionTool {
}
out.extend(frame_overlays(cx, &self.frame_anchors(cx)));
out.extend(type_path_handles(cx));
out.extend(picked_handle_overlays(cx, &self.picked_handles(cx)));
let drag = if let State::Bracket(b) = &self.state { Some(b) } else { None };
out.extend(pathtype::overlays(cx, self.bracket_hover, drag));
}
if matches!(self.state, State::Handle { .. } | State::MoveAnchors { .. } | State::MoveObject { .. }) {
if matches!(self.state, State::Handle { .. } | State::Handles { .. } | State::MoveAnchors { .. } | State::MoveObject { .. }) {
out.extend(self.guides.iter().cloned());
}
if let Some((id, p)) = self.hover.filter(|_| matches!(self.state, State::Idle)) {
@@ -1328,6 +1404,7 @@ impl Tool for DirectSelectionTool {
State::Segment { began: true, .. } | State::SpineSegment { began: true, .. } => return Cursor::ReshapeSegment,
// A drag shows the filled arrow, hollow while it snaps to a point or a guide.
State::Handle { .. }
| State::Handles { began: true, .. }
| State::SpineHandle { .. }
| State::SpinePoint { began: true, .. }
| State::TypeArea { began: true, .. }
@@ -1421,6 +1498,21 @@ fn hovered_anchor_with_hit(cx: &ToolContext, p: Point, hit: Option<&Hit>) -> Opt
/// The frame anchors of the selected area type and the path anchors of the selected type on a
/// path, which Direct Selection drags; the `selected` frame anchors are filled.
/// A ring around the end of each picked direction handle.
fn picked_handle_overlays(cx: &ToolContext, picked: &PickedHandles) -> Vec<Overlay> {
let mut out = vec![];
for (id, set) in picked {
let Some(pd) = cx.doc.node(*id).and_then(Node::path_data) else { continue };
let color = cx.doc.layer_color(*id);
for &(si, ai, h) in set {
if let Some(a) = pd.subpaths.get(si).and_then(|sp| sp.anchors.get(ai)) {
out.push(Overlay::CurvePoint { p: if h { a.h_out } else { a.h_in }, color, filled: false, size: 10.0 });
}
}
}
out
}
fn frame_overlays(cx: &ToolContext, selected: &[(NodeId, Vec<AnchorRef>)]) -> Vec<Overlay> {
let mut out = vec![];
for id in &cx.selection.objects {
@@ -1730,6 +1822,9 @@ impl DirectSelectionTool {
(id, si, ai, out): (NodeId, usize, usize, bool),
mut drag: HandleDrag,
) -> Vec<Action> {
if self.waits_for_drag(cx, p) {
return vec![];
}
let delta = p - drag.last;
if ev.mods.space {
drag.at += delta;
@@ -1776,6 +1871,128 @@ impl DirectSelectionTool {
self.state = State::Handle { id, si, ai, out, drag: Some(drag) };
vec![Action::Preview("path.setHandle".into(), params)]
}
/// A press on the end of the direction handle `(id, si, ai, out)`. Without Shift on one of two or
/// more picked handles (`picks`, as they were before the press), a drag moves them all; any
/// other press drags that handle alone, as before handles could be picked.
fn press_handle(
&mut self,
cx: &ToolContext,
ev: &PointerEvent,
p: Point,
(id, si, ai, out): (NodeId, usize, usize, bool),
picks: PickedHandles,
) -> Vec<Action> {
let drag = cx.doc.node(id).and_then(|n| match &n.kind {
NodeKind::Path { path, .. } => {
let a = path.subpaths.get(si)?.anchors.get(ai)?;
Some(HandleDrag {
at: a.p,
last: p,
handle: if out { a.h_out } else { a.h_in },
offset: Vec2::ZERO,
space: false,
independent: false,
symmetric: false,
translated: false,
})
}
_ => None,
});
self.handle_snap = HandleSnap::default();
// Only an ordinary path's handles are picked.
let Some(from) = drag.as_ref().map(|d| d.handle) else {
self.state = State::Handle { id, si, ai, out, drag };
return vec![Action::Begin("Reshape".into())];
};
let handle = (id, (si, ai, out));
let on = picks.get(&id).is_some_and(|set| set.contains(&handle.1));
let several = on && !ev.mods.shift && picks.values().map(BTreeSet::len).sum::<usize>() > 1;
let begin = if several {
let items = picks.iter().flat_map(|(id, set)| set.iter().map(|h| (*id, *h))).collect();
self.state = State::Handles { handle, from, start: p, items, began: false };
self.handles = picks.clone();
// The drag begins its undo step once it moves: a click picks the handle alone.
vec![]
} else {
self.state = State::Handle { id, si, ai, out, drag };
vec![Action::Begin("Reshape".into())]
};
self.handle_press = Some(HandlePress { handle, at: p, shift: ev.mods.shift, moved: false, picked: picks });
begin
}
/// The release of a press on one of several picked handles: a drag commits, and the picked
/// handles stay picked; a click picks the pressed handle alone.
fn release_handles(&mut self, handle: (NodeId, HandleRef), began: bool) -> Vec<Action> {
self.state = State::Idle;
self.guides.clear();
self.handle_press = None;
if began {
return vec![Action::Commit, Action::Notify(HANDLES_PICKED.into())];
}
self.handles = BTreeMap::from([(handle.0, BTreeSet::from([handle.1]))]);
vec![Action::Notify(HANDLES_PICKED.into())]
}
/// After the release of a press on a handle that did not drag: a click picks the handle alone,
/// and a Shift-click adds it to the picked handles or takes it away.
fn pick_clicked_handle(&mut self) -> Option<Action> {
let press = self.handle_press.take().filter(|press| !press.moved)?;
let (id, h) = press.handle;
let mut picked = if press.shift { press.picked } else { BTreeMap::new() };
let set = picked.entry(id).or_default();
if !set.remove(&h) {
set.insert(h);
}
if set.is_empty() {
picked.remove(&id);
}
self.handles = picked;
Some(Action::Notify(HANDLES_PICKED.into()))
}
/// Note whether the pointer of a press on a handle went past the drag distance. True while a
/// Shift-press has not: it may be a Shift-click that picks the handle, and moves nothing.
fn waits_for_drag(&mut self, cx: &ToolContext, p: Point) -> bool {
let Some(press) = &mut self.handle_press else { return false };
if !press.moved && p.distance(press.at) >= cx.tol(3.0) {
press.moved = true;
}
press.shift && !press.moved
}
/// Preview a drag of one of several picked handles: every picked handle moves by the offset the
/// pressed one moves by, which snaps as a single handle's drag does (Shift: along General ›
/// Constrain Angle's directions). Alt makes each of their anchors a corner.
fn drag_handles(
&mut self,
cx: &ToolContext,
ev: &PointerEvent,
p: Point,
handle: (NodeId, HandleRef),
(from, start, began): (Point, Point, bool),
items: Vec<(NodeId, HandleRef)>,
) -> Vec<Action> {
let mut out = vec![];
if !began {
if p.distance(start) < cx.tol(3.0) {
return out;
}
if let Some(press) = &mut self.handle_press {
press.moved = true;
}
out.push(Action::Begin("Reshape".into()));
}
let (id, (si, ai, _)) = handle;
let input = from + (p - start);
let (q, guides) = self.handle_snap.snap(cx, (id, si, ai), input, ev.mods.shift);
self.snapped = snapped(q.to_vec2(), input.to_vec2(), ev.mods.shift, &guides);
self.guides = guides;
let d = q - from;
let handles: Vec<Value> = items
.iter()
.map(|(id, (si, ai, out))| json!({"id": id.0, "subpath": si, "anchor": ai, "which": if *out { "out" } else { "in" }}))
.collect();
out.push(Action::Preview("path.moveHandles".into(), json!({"handles": handles, "dx": d.x, "dy": d.y, "independent": ev.mods.alt})));
self.state = State::Handles { handle, from, start, items, began: true };
out
}
fn drag_move_anchors(
&mut self,
+13
View File
@@ -7692,6 +7692,19 @@ request that leaves the anchor as it is records no undo step, and `link: true` w
("`link` and `independent` cannot both be true"), as is an x or y of 1e9 pt or more in size with `link: true`
("x and y must be finite"). `object.blend.spine.moveAnchor` takes `link` with `handle` in the
same way for a blend's spine point; without `handle` it is refused. These rules are VectorCraft's own.
`path.moveHandles {handles: [{id, subpath?, anchor, which}], dx, dy, independent?}` moves several direction handles,
on one path or several, by the same offset as one undo step. An anchor with one handle listed places it as
`path.setHandle` does, so a smooth anchor turns its other handle in line at its own length; an anchor with both handles
listed moves both and becomes a corner. `independent: true` makes the anchor of every listed handle a corner and leaves
its other handle where it is. A handle listed twice moves once, and a move by 0, 0 that makes no anchor a corner leaves
the document as it is and records no undo step. An empty or missing `handles`, a `which` other than `"in"` or `"out"`,
an object that is not a path, a missing subpath or anchor, a `dx` or `dy` that is missing, not a number or 1e9 pt or
more in size, and an `independent` that is not true or false are refused, and the document does not change. With Direct
Selection, a click on the end of a direction handle of a path picks that handle, a Shift-click adds it to the picked
handles or takes it away, and Escape lets them go; picked handles show ringed. A Shift-press on a handle moves it only
once the pointer has moved 3 pixels, so a Shift-click leaves it where it is. Dragging one of two or more picked handles
moves all of them by the offset of the dragged one (`path.moveHandles`), which snaps as a single handle's drag does,
and Alt sends `independent`; the handles stay picked after the drag. These rules are VectorCraft's own.
`path.insertAnchor` keeps the direct-selected anchors and selected segments of the path on the same points: those
after the new anchor on its subpath are numbered one higher, and a selected segment that the new anchor splits stays
selected as its two halves, with the new anchor as an end of both that moves with them. Undo restores the path and
+1
View File
@@ -1587,6 +1587,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Direct Selection (#1278):** clicking a segment picks its connection, with hollow endpoint anchors and only that curve's direction handles. Delete leaves the neighboring curves and appearance intact, opens/splits contours in one undo step, and another Delete removes the remaining selected path. A whole-path drag and deliberate anchor selection keep their existing behavior; egui frames and native control/art checked, OS mouse/visual QA pending. Where anchors of overlapping objects coincide, a click or drag takes the anchor of the selected object, also when another object lies over it (#1509, fixes #1508). Delete removes every selected anchor of a closed path (it used to remove the wrong ones), removes objects selected whole along with the selected anchors of others, and keeps the remainder selected so a second Delete removes it (#1674). In isolation mode Direct Selection and Group Selection pick only inside the isolated object (#1666). Escape cancels a Direct Selection drag (#1803, #1743). Double-clicking type (including type nested inside a group) switches to the Type tool and puts the caret at the clicked character.
With Direct Selection and Group Selection, a drag that starts on an object while the selection also holds direct-selected anchors or segments moves those anchors and the objects selected whole in one undo step (`path.moveAnchors`), as a drag of a selected anchor does, and the other anchors of a partly selected path stay in place. While Alt is held during the drag, it copies the selected objects instead (`object.transform`). When direct-selected anchors are moved or transformed together with objects selected whole (such a drag, an anchor drag, an arrow key, or Move, Rotate, Scale, Reflect and Shear without a copy), a path inside a selected group is transformed once, with the group.
VectorCraft's own preference General › Interpolate Control Points When Moving Anchors (`interpolateControlPoints`, off by default, fixes #7832): on, a Direct Selection drag, an arrow-key nudge, a Move or a Transform Again of selected anchors re-maps both handles of each segment with one moved end by the turn, uniform scale and move that take its old ends to its new ends, so a segment between corner anchors keeps its shape; a segment with both ends moved, or with its ends at the same place before or after the move, moves rigidly, and a smooth anchor keeps its handles in line. The commands take an `interpolate` param that defaults to the preference, and the value used joins the journal and Transform Again. Each drag or nudge is one undo step (`a_nudge_with_the_preference_on_re_maps_both_handles_of_the_segment`, `a_direct_selection_drag_with_the_preference_on_re_maps_the_handles_in_one_undo_step`, `a_smooth_anchor_keeps_its_handles_in_line`).
Picking several direction handles is VectorCraft's own behavior. With Direct Selection, a click on a path's direction handle picks it, a Shift-click adds or removes it without moving it, and Escape lets the picked handles go. Dragging one of two or more picked handles moves all of them, on one path or several, by the same offset in one undo step (`path.moveHandles`); an anchor with both handles picked becomes a corner, and Alt makes each moved handle's anchor a corner (`a_drag_of_one_of_two_picked_handles_moves_both_in_one_undo_step`, `shift_click_and_escape_let_picked_handles_go`, `both_handles_of_an_anchor_or_alt_make_a_corner` in `crates/engine/tests/it/several_handles.rs`).
VectorCraft's own preference General › Delete Removes Anchor Points and Keeps Paths Joined (`deleteKeepsPathsJoined`, off by default, part of #8326): on, Delete, Backspace and Edit › Clear remove the direct-selected anchors of each path as Remove Anchor Points does, refitting the curve around each one, so a closed path stays closed and an open path stays in one piece; the next anchor along (the one before at an open path's end) is selected, so the next Delete goes on along the path. Paths with a selected segment are still cut there, objects selected whole are still deleted, and a path left with fewer than two anchors goes, in one undo step. `edit.clear` takes a `keepJoined` param that defaults to the preference, and the value used joins the journal (`with_the_preference_on_delete_keeps_a_closed_path_closed_and_selects_the_next_anchor`, `several_paths_and_an_object_selected_whole_change_in_one_undo_step`, `with_the_preference_on_delete_and_backspace_keep_the_path_joined`).
VectorCraft's own preference General › Double-Click Adds Anchor Points (`doubleClickAddsAnchorPoints`, off by default, part of #8326): on, a double-click without modifier keys on a path segment with Direct Selection adds an anchor at the clicked point, keeping the curve's shape, with only the new anchor selected, in one undo step (`path.insertAnchor` with `selectAnchor`); on an anchor, a handle, a center point, a blend's spine point or a fill the double-click does what it did before, and a clipping path's segment gets the anchor (`with_the_preference_on_a_double_click_on_a_segment_adds_an_anchor_there`, `with_the_preference_on_a_double_click_in_a_group_adds_only_on_a_segment`, `with_the_preference_on_a_double_click_gives_way_to_spine_points_and_reaches_clipping_paths`, `with_the_preference_on_a_double_click_on_a_segment_adds_an_anchor_in_one_undo_step`, `the_double_click_and_delete_preferences_are_separate`).
A path segment with a control point whose x or y is infinite or larger in size than `f64::MAX / 16` is measured by its control points, so its bounds hold the whole curve and the canvas check refuses an edit that leaves such a path selected (`path.create` included).