From 2d3be0f51474242f2c6fc8acd7debb57cce86220 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 17:19:01 -0800 Subject: [PATCH 1/9] Pen: Quick Pen drags move a selected path's anchors and segments, and its context menu deletes With no path being drawn, the Quick Pen tool edits the selected paths, as the help page describes ("Drag the anchor points or the path to edit the object", and right-click Delete to remove a path): - A drag on an anchor moves it, and a drag that starts on one of several selected anchors moves them all; a drag on a segment moves its two ends. The tool selects what it moves (select.anchors or select.segments) and sends path.moveAnchors with interpolate, one undo step per drag, so a segment with one moved end is turned and scaled to its new ends: a line stays a line and an arc an arc of the same angle. A dragged anchor snaps to Smart Guides. Escape during the drag takes it back. - A click on an anchor selects it alone, and Shift-click adds it to the selected anchors or takes it out. A click on an open end still goes on drawing from it (with the path selected whole again), a drag there moves the end, and a click on a segment starts a new path. - With the Quick Pen chosen, the canvas context menu has Delete (edit.clear), which removes the selected anchors or objects. The cursor shows what a press does over an anchor, a selected anchor, an open end or a segment. While a path is being drawn, a press adds a piece as before. Which presses select and which move, and the drag snapping only an anchor, are VectorCraft's own rules. Docs: docs/mcp.md, ROADMAP, docs/target-app-parity.md, docs/ui-parity.md, crates/tools/src/cursors.toml. https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html --- ROADMAP.md | 1 + crates/engine/src/tests/quickpen.rs | 137 ++++++++++++++++++++++++ crates/tools/src/cursors.toml | 12 ++- crates/tools/src/quickpen.rs | 98 ++++++++++++++--- crates/tools/src/quickpen/edit.rs | 134 +++++++++++++++++++++++ crates/tools/src/quickpen/tests.rs | 28 +++++ crates/ui-egui/src/menus/context.rs | 10 +- crates/ui-egui/src/tests/contextmenu.rs | 21 ++++ docs/mcp.md | 15 +++ docs/target-app-parity.md | 1 + docs/ui-parity.md | 2 +- 11 files changed, 443 insertions(+), 16 deletions(-) create mode 100644 crates/tools/src/quickpen/edit.rs diff --git a/ROADMAP.md b/ROADMAP.md index 90a6100167..7c7bc4cd7c 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -149,6 +149,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap - 2026-11-17: Circle Tool Options (double-click the Circle tool): Show Center, Show Radii and Show Diameter switch what the tool shows while a circle is drawn, Color sets the color of the center cross and radius lines, Anchors at Standard Positions off puts the circle's anchors at the points it was drawn through (`shape.circleThroughPoints {anchors: "points"}`), and Third Point by Dragging off draws a three-point circle with three clicks and a two-point circle with a double-click on the second point. A VectorCraft addition: headline numbers unchanged. - 2026-11-19: Quick Pen tool, in the Pen tool's group (Alt+P, Option+P on macOS): clicks or drags add straight lines, continuous arcs or sharp-corner arcs; Alt tapped on its own switches the action, C flips the last arc, `[` and `]` size it, a click on the first point closes the path and a click on an open end continues it (`path.quickPen`, part of #2660). Headline numbers unchanged. - 2026-11-19: Quick Pen toolbar on the canvas while the tool is active: Straight Line, Continuous Arc and Sharp Corner Arc, Flip Arc, and More Options with Hide Toolbar, Pin Toolbar Position and Reset Toolbar Position; it follows the drawing beside the path's last point and its handle drags it (`tool.quickPen.flipArc`, `window.quickPenToolbar`, Window › Quick Pen Toolbar; part of #2660). Headline numbers unchanged. +- 2026-11-19: Quick Pen editing: with no path being drawn, a drag on an anchor or a segment of a selected path moves it, a line staying a line and an arc an arc; a click selects an anchor, Shift-click adds one, and the canvas context menu's Delete removes the selected anchors (`path.moveAnchors`, `edit.clear`; #2660). Headline numbers unchanged. - 2026-10-31: Pattern libraries: Window › Swatch Libraries › Patterns and the Swatches panel's library menu open Geometric Patterns, a built-in library of eleven pattern swatches (dots, stripes, checks, a grid and shapes); clicking one adds its pattern and swatch to the document, once, and applies it to the active fill or stroke (`swatch.library.add`). - 2026-11-11: Pattern libraries: Patterns › Grit Textures, a second built-in pattern library, holds eight seamless black textures (Fine Grain, Coarse Grit, Sand, Speckle, Stipple, Scratches, Sparse Flecks and Dense Flecks) on tiles of 18 to 36 pt, each drawn the same way every time; marks that reach past a tile edge continue on the next tile, so the tiles join without a seam (`swatch.library.add`). Scores and estimates unchanged. - 2026-11-11: Pattern libraries: Patterns › Optical Effects, a third built-in pattern library, of VectorCraft's own designs, holds eight black wave, moiré and op-art tiles (Sine Bands, Ripple Lines, Interference Rings, Offset Rings, Warped Checks, Pinched Stripes, Chevron Pulse and Radiating Lenses) of 32 to 48 pt, each drawn the same way every time; each tile is one period of its design, and art that reaches past a tile edge continues on the next tile, so the tiles join without a seam (`swatch.library.add`). Scores and estimates unchanged. diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index f14be809b4..5f41ecedb7 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -562,3 +562,140 @@ fn path_quick_pen_replaces_the_points_after_keep() { let ends: Vec = only_path(&s).anchors.iter().map(|a| a.p).collect(); assert_eq!(ends, [pt(0.0, 0.0), pt(100.0, 0.0), pt(200.0, 0.0)]); } + +/// A selected path drawn with `path.quickPen` from `start` through `pieces`, with the Quick Pen +/// chosen and no path being drawn. +fn selected_quick_pen_path(s: &mut Session, start: (f64, f64), pieces: Value) -> NodeId { + let r = s.execute("path.quickPen", &json!({"start": [start.0, start.1], "pieces": pieces})).unwrap(); + let id = NodeId(r["id"].as_u64().unwrap()); + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + quick_pen(s); + id +} + +fn points(s: &Session) -> Vec { + only_path(s).anchors.iter().map(|a| a.p).collect() +} + +fn shift_click(s: &mut Session, x: f64, y: f64) { + let v = view(); + let mods = Mods { shift: true, ..Mods::default() }; + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent { mods, ..PointerEvent::new(kind, x, y) }, v).unwrap(); + } +} + +/// Is segment `i` of `sp` a circular arc: do its points a quarter and three quarters along lie on +/// the circle through its ends and its middle? +fn segment_is_circular(sp: &SubPath, i: usize) -> bool { + use vectorcraft_geom::ParamCurve; + let seg = sp.segment(i); + let (a, b, c) = (seg.eval(0.0), seg.eval(0.5), seg.eval(1.0)); + let d = 2.0 * (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)); + let sq = |p: Point| p.x * p.x + p.y * p.y; + let center = pt( + (sq(a) * (b.y - c.y) + sq(b) * (c.y - a.y) + sq(c) * (a.y - b.y)) / d, + (sq(a) * (c.x - b.x) + sq(b) * (a.x - c.x) + sq(c) * (b.x - a.x)) / d, + ); + let r = center.distance(a); + [0.25, 0.75].iter().all(|&t| (seg.eval(t).distance(center) - r).abs() < r * 1e-3) +} + +/// With no path being drawn, a drag on an anchor of the selected path moves that anchor alone, in +/// one undo step: at the corner between a line and an arc, the line stays a line and the arc a +/// circular arc. +#[test] +fn a_drag_on_an_anchor_moves_it_and_the_arc_stays_an_arc() { + let mut s = session(); + selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100, "action": "sharpArc", "turn": 90}])); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 100.0), pt(300.0, 100.0)]); + let undo = undo_steps(&s); + press(&mut s, &[(200.0, 100.0), (200.0, 80.0), (200.0, 50.0)]); + assert_eq!(undo_steps(&s), undo + 1); + let sp = only_path(&s); + assert_eq!(sp.anchors.iter().map(|a| a.p).collect::>(), [pt(100.0, 100.0), pt(200.0, 50.0), pt(300.0, 100.0)]); + assert!(sp.segment_is_line(0), "{:?}", sp.anchors); + assert!(!sp.segment_is_line(1) && segment_is_circular(&sp, 1), "{:?}", sp.anchors); + assert_eq!(paths(&s).len(), 1, "no new path"); +} + +/// A drag on a segment of the selected path moves that segment's two ends. +#[test] +fn a_drag_on_a_segment_moves_its_ends() { + let mut s = session(); + selected_quick_pen_path(&mut s, (100.0, 300.0), json!([{"x": 300, "y": 300}, {"x": 300, "y": 400}])); + press(&mut s, &[(200.0, 300.0), (200.0, 280.0), (200.0, 250.0)]); + assert_eq!(points(&s), [pt(100.0, 250.0), pt(300.0, 250.0), pt(300.0, 400.0)]); + assert_eq!(paths(&s).len(), 1); +} + +/// A drag that starts on an end of the selected open path moves that end; a click there still +/// goes on drawing from it. +#[test] +fn a_drag_on_an_open_end_moves_it() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 300.0), json!([{"x": 300, "y": 300}])); + press(&mut s, &[(300.0, 300.0), (320.0, 320.0), (350.0, 350.0)]); + assert_eq!(points(&s), [pt(100.0, 300.0), pt(350.0, 350.0)]); + assert!(s.doc().unwrap().selection.partial(id).is_some(), "the dragged end is selected"); + click(&mut s, 350.0, 350.0); + assert!(s.doc().unwrap().selection.partial(id).is_none(), "drawing goes on with the path selected whole"); + click(&mut s, 350.0, 450.0); + assert_eq!(points(&s), [pt(100.0, 300.0), pt(350.0, 350.0), pt(350.0, 450.0)]); +} + +/// A click on an anchor selects it alone, Shift-click adds another, and Delete (`edit.clear`, the +/// context menu's Delete) then removes both. +#[test] +fn clicks_select_anchors_for_delete() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}, {"x": 400, "y": 100}])); + let undo = undo_steps(&s); + click(&mut s, 200.0, 100.0); + let picked = |s: &Session| s.doc().unwrap().selection.partial(id).cloned().unwrap_or_default().into_iter().collect::>(); + assert_eq!(picked(&s), [(0, 1)]); + shift_click(&mut s, 300.0, 100.0); + assert_eq!(picked(&s), [(0, 1), (0, 2)]); + shift_click(&mut s, 300.0, 100.0); + assert_eq!(picked(&s), [(0, 1)], "Shift-click takes it out again"); + shift_click(&mut s, 300.0, 100.0); + assert_eq!(undo_steps(&s), undo, "selecting is no edit"); + s.execute("edit.clear", &json!({})).unwrap(); + let left: Vec = paths(&s).iter().flat_map(|(_, pd)| pd.subpaths.iter().flat_map(|sp| sp.anchors.iter().map(|a| a.p))).collect(); + assert!(!left.contains(&pt(200.0, 100.0)) && !left.contains(&pt(300.0, 100.0)), "{left:?}"); +} + +/// Escape during a drag puts the anchor back, and the release then changes nothing. +#[test] +fn escape_takes_back_an_anchor_drag() { + let mut s = session(); + selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let (before, undo) = (points(&s), undo_steps(&s)); + let v = view(); + s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 100.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 150.0), v).unwrap(); + assert_ne!(points(&s), before, "the drag previews"); + key(&mut s, ToolKey::Escape); + s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 150.0), v).unwrap(); + assert_eq!(points(&s), before); + assert_eq!(undo_steps(&s), undo); + assert_eq!(paths(&s).len(), 1); +} + +/// While a path is being drawn, a press on one of its points adds a piece as before; the editing +/// starts only after Escape ends the path. +#[test] +fn a_press_while_drawing_adds_a_piece() { + let mut s = session(); + quick_pen(&mut s); + click(&mut s, 100.0, 100.0); + click(&mut s, 200.0, 100.0); + click(&mut s, 200.0, 200.0); + press(&mut s, &[(200.0, 100.0), (220.0, 90.0), (250.0, 80.0)]); + assert_eq!(points(&s).len(), 4, "a piece added"); + key(&mut s, ToolKey::Escape); + press(&mut s, &[(200.0, 100.0), (200.0, 70.0), (200.0, 50.0)]); + let got = points(&s); + assert_eq!(got.len(), 4); + assert!(got[1].distance(pt(200.0, 50.0)) < 1e-9, "{got:?}"); +} diff --git a/crates/tools/src/cursors.toml b/crates/tools/src/cursors.toml index 0d0106eddb..0b19e3e4c0 100644 --- a/crates/tools/src/cursors.toml +++ b/crates/tools/src/cursors.toml @@ -47,14 +47,20 @@ look = "The same pointer as Arrow, hollow: white with a dark outline." [[cursor]] id = "DirectAnchor" group = "Selection" -shown_when = ["Direct Selection over an anchor of a path that isn't selected."] +shown_when = [ + "Direct Selection over an anchor of a path that isn't selected.", + "The Quick Pen, with no path being drawn, over an anchor of a selected path that is not itself selected (a click selects it, a drag moves it).", +] hotspot = "The arrow's tip." look = "ArrowHollow with a small hollow square badge (an unselected anchor)." [[cursor]] id = "DirectAnchorSelected" group = "Selection" -shown_when = ["Direct Selection over an anchor of a selected path."] +shown_when = [ + "Direct Selection over an anchor of a selected path.", + "The Quick Pen, with no path being drawn, over a selected anchor.", +] hotspot = "The arrow's tip." look = "ArrowHollow with a small filled square badge (a selected anchor)." @@ -137,6 +143,7 @@ shown_when = [ "The Gradient tool over the annotator's handles and during most gradient drags.", "The Perspective Grid and Perspective Selection over plane widgets and handles.", "Selection and Objects on Path over an Objects on Path group's Move All widget, and while dragging it.", + "The Quick Pen, with no path being drawn, over a segment of a selected path, and while a drag moves an anchor or a segment.", ] hotspot = "The centre." look = "A four-way move cursor." @@ -242,6 +249,7 @@ group = "Pen" shown_when = [ "The Pen (not drawing) over an end of an open path (a click continues it).", "The Curvature tool over an open end.", + "The Quick Pen (not drawing) over an end of an open path (a click continues it, a drag on a selected path's end moves it).", ] hotspot = "The nib's tip." look = "The Pen nib with a slash badge." diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index 6368ba160b..290c0f494a 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -12,6 +12,9 @@ //! point closes the path, a click on an end of an open path goes on drawing from it, and Escape //! or Enter ends the path. The path's points show as circles, without handles, and a preview //! shows the piece the next click adds. Points snap to Smart Guides. Each piece is one undo step. +//! While no path is being drawn, the tool edits the selected paths ([`edit`]). + +mod edit; use std::f64::consts::{FRAC_PI_2, PI}; use std::sync::Arc; @@ -24,6 +27,7 @@ use crate::draw2::FEEDBACK; use crate::guides::{DrawSnap, Leave}; use crate::pen::{continue_from, open_end_at}; use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, ToolContext, ToolKey}; +use edit::{Edit, Grab}; /// The tool's id. pub const ID: &str = "quickPen"; @@ -282,13 +286,15 @@ pub struct QuickPenTool { turn: f64, drawing: Option, press: Option, + /// A press on an anchor or a segment of a selected path while no path is being drawn. + edit: Option, hover: Option, snap: DrawSnap, } impl Default for QuickPenTool { fn default() -> Self { - Self { action: Stroke::Line, turn: DEFAULT_TURN, drawing: None, press: None, hover: None, snap: DrawSnap::default() } + Self { action: Stroke::Line, turn: DEFAULT_TURN, drawing: None, press: None, edit: None, hover: None, snap: DrawSnap::default() } } } @@ -409,8 +415,9 @@ impl QuickPenTool { } /// What a press draws: a piece on the path being drawn, its closing piece, or a new path (from - /// an end of an open path, the path goes on). - fn press_down(&mut self, cx: &ToolContext, p: Point) -> Vec { + /// an end of an open path, the path goes on). With no path being drawn, a press on an anchor + /// or a segment of a selected path waits to see whether it drags ([`edit`]). + fn press_down(&mut self, cx: &ToolContext, p: Point, shift: bool) -> Vec { if self.drawing.is_some() && self.active(cx).is_none() { self.drawing = None; } @@ -442,30 +449,75 @@ impl QuickPenTool { self.press = Some(Press { at: p, dragged: false, begun: true }); return vec![Action::Begin("Quick Pen".into()), Action::Preview(COMMAND.into(), self.params(false)), drawn()]; } + if let Some(grab) = edit::grab_at(cx, p, tol) { + self.edit = Some(Edit::new(grab, p, shift)); + return vec![]; + } if let Some((id, si, at_first)) = open_end_at(cx, p, tol, None) && cx.doc.is_editable(id) { - // From its start, `continue_from` reverses the path first; the tool then sees it. - self.drawing = Some(Drawing { id: Some(id), si, ..Drawing::default() }); - let mut out = continue_from(cx, id, si, at_first); - out.push(drawn()); - return out; + return self.continue_path(cx, id, si, at_first); } + self.start_path(cx, p) + } + + /// Goes on drawing from an end of subpath `si` of path `id`. + fn continue_path(&mut self, cx: &ToolContext, id: NodeId, si: usize, at_first: bool) -> Vec { + // From its start, `continue_from` reverses the path first; the tool then sees it. + self.drawing = Some(Drawing { id: Some(id), si, ..Drawing::default() }); + let mut out = vec![]; + // Anchors selected by an earlier click or drag: the path is selected whole again. + if !cx.selection.anchors.is_empty() || !cx.selection.segments.is_empty() { + let top = cx.doc.parent_of(id).filter(|p| cx.doc.node(*p).is_some_and(|n| matches!(n.kind, NodeKind::Compound { .. }))).unwrap_or(id); + out.push(Action::Exec("select.set".into(), json!({"ids": [top.0]}))); + } + out.extend(continue_from(cx, id, si, at_first)); + out.push(drawn()); + out + } + + /// Starts a new path at `p`. + fn start_path(&mut self, cx: &ToolContext, p: Point) -> Vec { let q = self.snap.press(cx, p, &[], None); self.drawing = Some(Drawing { start: Some(q), ..Drawing::default() }); vec![Action::Exec(COMMAND.into(), self.params(false)), Action::Notify("created".into())] } - /// Ends the path being drawn; a press that added a piece is taken back. + /// Ends the path being drawn; a press that added a piece, or moved part of a path, is taken + /// back. fn end(&mut self) -> Vec { self.drawing = None; self.snap.clear(); + let moved = self.edit.take().is_some_and(|e| e.began); match self.press.take() { Some(pr) if pr.begun => vec![Action::Cancel], + _ if moved => vec![Action::Cancel], _ => vec![], } } + /// The release of a press on an anchor or a segment of a selected path: a drag moves what it + /// holds to `p` and ends its undo step. A click on an end of an open path goes on drawing from + /// it, a click on another anchor selects it alone (with Shift, adds it to the selected anchors + /// or takes it out), and a click on a segment starts a new path there. + fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { + if e.began { + let mut out = e.drag(cx, p); + out.push(Action::Commit); + return out; + } + match e.grab { + Grab::Anchor { id, si, ai, .. } if e.shift => { + vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "toggle"}))] + } + Grab::Anchor { id, si, ai, end: true, .. } => self.continue_path(cx, id, si, ai == 0), + Grab::Anchor { id, si, ai, .. } => { + vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "set"}))] + } + Grab::Segment { .. } => self.start_path(cx, e.start), + } + } + /// The piece the next click adds, from the end of `sp` to `h`, as a path to preview. fn rubber_band(&self, sp: &SubPath, h: Point) -> Option { let n = sp.anchors.len(); @@ -490,7 +542,7 @@ impl Tool for QuickPenTool { } fn busy(&self) -> bool { - self.press.is_some() + self.press.is_some() || self.edit.is_some() } fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec { @@ -502,12 +554,18 @@ impl Tool for QuickPenTool { vec![] } PointerKind::Down => { - if self.press.is_some() { + if self.press.is_some() || self.edit.is_some() { return vec![]; } - self.press_down(cx, p) + self.press_down(cx, p, ev.mods.shift) } PointerKind::Drag => { + if let Some(e) = self.edit.as_mut() { + if !e.began && p.distance(e.start) < cx.tol(DRAG_PX) { + return vec![]; + } + return e.drag(cx, p); + } let Some(mut pr) = self.press else { return vec![] }; if !pr.dragged && p.distance(pr.at) < cx.tol(DRAG_PX) { return vec![]; @@ -520,6 +578,9 @@ impl Tool for QuickPenTool { self.drag_to(cx, p) } PointerKind::Up => { + if let Some(e) = self.edit.take() { + return self.release_edit(cx, e, p); + } let out = match self.press { // The piece ends where the press is let go, also past the last drag. Some(pr) if pr.begun => { @@ -595,6 +656,8 @@ impl Tool for QuickPenTool { /// The drawing goes on only when the path is back as it was before the press. fn drop_press(&mut self, cx: &ToolContext) -> Vec { self.snap.clear(); + // The session takes back what an edit moved; the release that follows does nothing. + self.edit = None; if self.press.take().is_some_and(|pr| pr.begun) && let Some(dr) = self.drawing.as_mut() { @@ -655,8 +718,10 @@ impl Tool for QuickPenTool { fn deactivate(&mut self, _cx: &ToolContext) -> Vec { self.drawing = None; self.snap.clear(); + let moved = self.edit.take().is_some_and(|e| e.began); match self.press.take() { Some(pr) if pr.begun => vec![Action::Commit], + _ if moved => vec![Action::Commit], _ => vec![], } } @@ -674,6 +739,9 @@ impl Tool for QuickPenTool { fn overlays(&self, cx: &ToolContext) -> Vec { let mut o = self.snap.guides().to_vec(); + if let Some(e) = &self.edit { + o.extend(e.guides.iter().cloned()); + } let Some((id, sp)) = self.active(cx) else { return o }; if self.press.is_none() && let Some(h) = self.hover @@ -703,6 +771,12 @@ impl Tool for QuickPenTool { let close = sp.anchors.len() >= 2 && sp.anchors.first().is_some_and(|f| f.p.distance(p) <= tol); return if close { Cursor::PenClose } else { Cursor::PenDrawing }; } + if let Some(e) = &self.edit { + return if e.began { Cursor::Move } else { edit::cursor(cx, e.grab) }; + } + if let Some(grab) = edit::grab_at(cx, p, tol) { + return edit::cursor(cx, grab); + } if open_end_at(cx, p, tol, None).is_some() { Cursor::PenContinue } else { Cursor::Pen } } diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs new file mode 100644 index 0000000000..ee219a8d63 --- /dev/null +++ b/crates/tools/src/quickpen/edit.rs @@ -0,0 +1,134 @@ +//! Editing with the Quick Pen while no path is being drawn: a drag on an anchor of a selected path +//! moves it, and a drag on one of its segments moves that segment (`path.moveAnchors` with +//! `interpolate`: a segment with one moved end is turned and scaled to its new ends, so a line +//! stays a line and an arc stays an arc of the same angle; at a smooth point, where two arcs join, +//! the handles stay in line and the arcs bend to meet). The moved anchor snaps as a Direct +//! Selection drag's does. A click on an anchor selects it, Shift-click adds it to the selected anchors or takes it +//! out, and the canvas context menu's Delete then removes them (`edit.clear`). A click on an end +//! of an open path goes on drawing from it, as before. + +use std::collections::BTreeSet; + +use serde_json::json; +use vectorcraft_doc::{AnchorRef, NodeId, Selection}; +use vectorcraft_geom::Point; + +use crate::draw2::{anchor_in, segment_in, shown_paths}; +use crate::guides::{PointSnap, Targets}; +use crate::{Action, Cursor, Overlay, ToolContext}; + +/// What a press holds. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(super) enum Grab { + /// Anchor `ai` of subpath `si` of path `id`, at `at`; `end` when it is an end of an open subpath. + Anchor { id: NodeId, si: usize, ai: usize, at: Point, end: bool }, + /// The segment from anchor `seg` of subpath `si` of path `id` to the next one. + Segment { id: NodeId, si: usize, seg: usize }, +} + +impl Grab { + /// The path the grab is on. + pub(super) fn id(self) -> NodeId { + match self { + Grab::Anchor { id, .. } | Grab::Segment { id, .. } => id, + } + } + + /// The anchors the drag moves when they are not already selected: the anchor, or the + /// segment's two ends. + fn anchors(self, cx: &ToolContext) -> Option> { + match self { + Grab::Anchor { si, ai, .. } => Some(vec![(si, ai)]), + Grab::Segment { id, si, seg } => { + let n = cx.doc.node(id)?.path_data()?.subpaths.get(si)?.anchors.len(); + Some(vec![(si, seg), (si, (seg + 1).checked_rem(n)?)]) + } + } + } +} + +/// An anchor or a segment of a selected path under `p`, within the tool's point tolerance `tol`. +/// Anchors come before segments. +pub(super) fn grab_at(cx: &ToolContext, p: Point, tol: f64) -> Option { + let shown = shown_paths(cx); + if let Some((id, si, ai)) = anchor_in(cx, shown.iter().copied(), p, tol) { + let sp = cx.doc.node(id)?.path_data()?.subpaths.get(si)?; + let at = sp.anchors.get(ai)?.p; + let end = !sp.closed && (ai == 0 || ai + 1 == sp.anchors.len()); + return Some(Grab::Anchor { id, si, ai, at, end }); + } + segment_in(cx, shown, p, tol).map(|(id, si, seg, _)| Grab::Segment { id, si, seg }) +} + +/// The cursor over `grab`: an open end shows that a click goes on drawing from it, another anchor +/// that it can be selected and moved, and a segment that it moves. +pub(super) fn cursor(cx: &ToolContext, grab: Grab) -> Cursor { + match grab { + Grab::Anchor { end: true, .. } => Cursor::PenContinue, + Grab::Anchor { id, si, ai, .. } if cx.selection.partial(id).is_some_and(|s| s.contains(&(si, ai))) => Cursor::DirectAnchorSelected, + Grab::Anchor { .. } => Cursor::DirectAnchor, + Grab::Segment { .. } => Cursor::Move, + } +} + +/// A press on an anchor or a segment of a selected path, while no path is being drawn. +pub(super) struct Edit { + pub(super) grab: Grab, + /// Where the press went down. + pub(super) start: Point, + pub(super) shift: bool, + /// Whether the press has dragged far enough to move what it holds (an undo step began). + pub(super) began: bool, + snap: Option, + pub(super) guides: Vec, +} + +impl Edit { + pub(super) fn new(grab: Grab, start: Point, shift: bool) -> Self { + Self { grab, start, shift, began: false, snap: None, guides: vec![] } + } + + /// Moves what the press holds by the drag to `p`. The first move selects the anchor, or the + /// segment, unless it is already selected, and begins the undo step; a drag that starts on + /// one of several selected anchors moves them all. + pub(super) fn drag(&mut self, cx: &ToolContext, p: Point) -> Vec { + let mut out = vec![]; + if !self.began { + let id = self.grab.id(); + let Some(picked) = self.grab.anchors(cx) else { return out }; + let already = cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a))); + let moving = if already { + cx.selection.clone() + } else { + out.push(match self.grab { + Grab::Anchor { si, ai, .. } => Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "set"})), + Grab::Segment { si, seg, .. } => { + Action::Exec("select.segments".into(), json!({"id": id.0, "segments": [[si, seg]], "mode": "set"})) + } + }); + let mut sel = Selection { objects: vec![id], ..Selection::default() }; + sel.anchors.insert(id, picked.into_iter().collect::>()); + sel + }; + out.push(Action::Begin("Move".into())); + // A held anchor snaps; the anchors and segments that stay put are targets too. + if matches!(self.grab, Grab::Anchor { .. }) { + self.snap = Some(PointSnap::moving(cx, || Targets::for_anchor_drag(cx.doc, &moving))); + } + self.began = true; + } + let d = match (self.grab, &self.snap) { + (Grab::Anchor { at, .. }, Some(snap)) => { + let (q, guides) = snap.snap_from(cx, at + (p - self.start), None); + self.guides = guides; + q - at + } + _ => p - self.start, + }; + if !d.x.is_finite() || !d.y.is_finite() { + return out; + } + out.push(Action::Preview("path.moveAnchors".into(), json!({"dx": d.x, "dy": d.y, "interpolate": true}))); + out + } +} diff --git a/crates/tools/src/quickpen/tests.rs b/crates/tools/src/quickpen/tests.rs index f5ab9986d1..0d316c8428 100644 --- a/crates/tools/src/quickpen/tests.rs +++ b/crates/tools/src/quickpen/tests.rs @@ -196,6 +196,34 @@ fn the_first_click_starts_a_path() { assert_eq!(t.cursor(&cx, pt(400.0, 400.0), Mods::default()), Cursor::Pen); } +/// With no path being drawn, the cursor over a selected path shows what a press there does: an +/// anchor is selected and moved, a selected anchor shows as one, and a segment moves. A press there +/// waits for a drag or a release instead of starting a path. +#[test] +fn a_selected_paths_anchors_and_segments_show_the_edit_cursors() { + let (d, id) = doc_with_rect(); + let mut s = Selection::default(); + s.set([id]); + let p = paint(); + let cx = cx(&d, &s, &p); + let mut t = QuickPenTool::default(); + assert_eq!(t.cursor(&cx, pt(100.0, 100.0), Mods::default()), Cursor::DirectAnchor); + assert_eq!(t.cursor(&cx, pt(150.0, 100.0), Mods::default()), Cursor::Move); + assert_eq!(t.cursor(&cx, pt(400.0, 400.0), Mods::default()), Cursor::Pen); + assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 150.0, 100.0)).is_empty()); + assert!(t.busy()); + let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 150.0, 130.0)); + assert!(matches!(&a[0], Action::Exec(c, v) if c == "select.segments" && v["mode"] == "set"), "{a:?}"); + assert!(matches!(&a[2], Action::Preview(c, v) if c == "path.moveAnchors" && v["dy"] == 30.0 && v["interpolate"] == true), "{a:?}"); + assert_eq!(t.cursor(&cx, pt(150.0, 130.0), Mods::default()), Cursor::Move); + let up = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 150.0, 130.0)); + assert_eq!(up.last(), Some(&Action::Commit)); + assert!(!t.busy()); + s.anchors.insert(id, (0..4).map(|ai| (0, ai)).collect()); + let cx = crate::testutil::cx(&d, &s, &p); + assert_eq!(t.cursor(&cx, pt(100.0, 100.0), Mods::default()), Cursor::DirectAnchorSelected); +} + /// The rubber band previews exactly the piece a click adds. #[test] fn the_rubber_band_is_the_next_piece() { diff --git a/crates/ui-egui/src/menus/context.rs b/crates/ui-egui/src/menus/context.rs index d80b69038b..004ee0e37a 100644 --- a/crates/ui-egui/src/menus/context.rs +++ b/crates/ui-egui/src/menus/context.rs @@ -54,7 +54,15 @@ pub fn context_items(app: &VectorcraftApp) -> Vec { c("Select All", "select.all"), ]); } else { - v.extend([c("Cut", "edit.cut"), c("Copy", "edit.copy"), c("Paste", "edit.paste"), Sep]); + v.extend([c("Cut", "edit.cut"), c("Copy", "edit.copy"), c("Paste", "edit.paste")]); + // With the Quick Pen, Delete removes the selected anchor points, or the selected objects + // (`edit.clear`), as the public + // [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) + // page describes for removing a path. + if app.session.tool_id() == vectorcraft_tools::quickpen::ID { + v.push(c("Delete", "edit.clear")); + } + v.push(Sep); // With one group or compound path selected the menu has Isolate Selected Group, and with // one path selected (a member of a group or a compound path too) it has Isolate Selected // Path, as the help page diff --git a/crates/ui-egui/src/tests/contextmenu.rs b/crates/ui-egui/src/tests/contextmenu.rs index 781924d1a1..afe854c6a8 100644 --- a/crates/ui-egui/src/tests/contextmenu.rs +++ b/crates/ui-egui/src/tests/contextmenu.rs @@ -214,6 +214,27 @@ fn labels(items: &[Item]) -> Vec<&'static str> { .collect() } +/// With the Quick Pen, the menu has Delete, which removes the selected anchor points; with another +/// tool it does not. +#[test] +fn the_quick_pen_menu_deletes_the_selected_anchors() { + let mut app = app(); + let a = rect(&mut app, 0.0, 0.0); + app.run("select.anchors", json!({"id": a.0, "anchors": [[0, 0]], "mode": "set"})).unwrap(); + assert!(!labels(&menus::context_items(&app)).contains(&"Delete"), "the Selection tool"); + app.select_tool("quickPen"); + let items = menus::context_items(&app); + assert!(labels(&items).contains(&"Delete"), "{:?}", labels(&items)); + assert!(items.iter().any(|it| matches!(it, Item::Cmd("Delete", "edit.clear", _)))); + menus::invoke(&mut app, "edit.clear", json!({})); + let st = app.session.active().unwrap(); + let pd = st.doc.node(a).unwrap().path_data().unwrap().clone(); + assert_eq!(pd.subpaths[0].anchors.len(), 3, "one anchor removed"); + // Nothing selected: no Delete. + app.run("select.none", json!({})).unwrap(); + assert!(!labels(&menus::context_items(&app)).contains(&"Delete")); +} + #[test] fn the_menu_follows_the_selection() { let mut app = app(); diff --git a/docs/mcp.md b/docs/mcp.md index e7abf476a9..add7833de6 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7339,6 +7339,21 @@ toolbar its controls wrap onto more rows. `ui.inspect` gives `quickPenToolbar` ( the pin and whether it shows are not saved. These commands run in the desktop app; the headless host does not run them, so they need `--connect`. +With no path being drawn (after Escape or Enter, or before the first click), the tool edits the selected paths, as +[Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) +describes. A drag on one of their anchors moves that anchor, and a drag that starts on one of several selected anchors +moves them all; a drag on a segment moves that segment's two ends. The tool selects what it moves +(`select.anchors` or `select.segments` with `mode: "set"`) and moves it with `path.moveAnchors {dx, dy, interpolate: +true}`, one undo step per drag: a segment with one moved end is turned and scaled to its new ends, so a line stays a +line and an arc stays an arc through the same angle, and at a smooth point the handles stay in line. A dragged anchor +snaps to Smart Guides; a dragged segment does not. Escape during the drag takes it back. A click on an anchor selects +it alone and Shift-click adds it to the selected anchors or takes it out (`select.anchors` with `"set"` or +`"toggle"`). A click on an end of an open path still goes on drawing from it, a drag there moves the end, and a click +on a segment starts a new path. With the Quick Pen chosen, the canvas context menu (right-click) has Delete, which +removes the selected anchors, or the selected objects (`edit.clear {}`). While a path is being drawn, a press on it +adds a piece as before. Which presses select, which move, and the drag snapping only an anchor are VectorCraft's own +rules. + `path.quickPen {start?: [x, y], id?, subpath?, keep?, pieces?, closed?}` draws such a path and selects it, as one undo step, and answers `{id}`. With `start`, it makes a new path with the current paint (a black stroke when the paint has neither fill nor stroke). With `id`, it draws on the open subpath `subpath` (0 when left out) of that path: its diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index b1d981428a..5058e1f6df 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -634,6 +634,7 @@ since 2026-10-01. - **Trim View hides guides and the grid (#8363):** while View › Trim View is on, the canvas and tiled panes draw no ruler guides, no guide paths and no grid, the guides are neither snapped to nor picked, and Show/Hide Guides and Show/Hide Grid are greyed out (menu bar, canvas context menu, Properties) and refuse to run; the stored choices come back when it is turned off, and the rulers stay ([trim view hides guides](https://community.adobe.com/t5/illustrator-discussions/trim-view-hides-guides/td-p/14066140), [guides greyed out](https://community.adobe.com/t5/illustrator-discussions/guides-greyed-out/m-p/11132728)). A drag or double-click on a ruler makes no guide while it is on (no preview, no undo step, a status message). `trim_view_hides_the_guides_and_the_grid`, `trim_view_deselects_selected_guide_paths`, `trim_view_makes_no_guide_from_the_rulers` in `crates/ui-egui/src/canvas/tests.rs`; `trim_view_greys_out_show_guides_and_show_grid` in `crates/ui-egui/src/menus/tests.rs`. - **Recolor picker follow-up (#8031/#4028):** native Lab numeric entry, document/loaded-library swatches in the Color Picker, and Assign-row Pick from Swatches / Limit to Library menus. #4090 provided the double-click picker and #5113 the Assign sliders. Regression tests `native_lab_entry_in_color_picker` and `row_context_menu_pick_from_swatches_and_limit_to_library` exercise the fields and menu callbacks rather than writing their result state. Area score and hours unchanged. +- **Quick Pen editing (#2660):** with no path being drawn, the Quick Pen tool moves an anchor or a segment of a selected path by a drag (`path.moveAnchors` with `interpolate`, one undo step, a line staying a line and an arc an arc), selects an anchor with a click and adds one with Shift-click, and the canvas context menu's Delete removes the selected anchors (`edit.clear`), as [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) describes. Which presses select and which move, and the drag snapping only an anchor, are VectorCraft's own rules. Tests: tools `quickpen::tests::a_selected_paths_anchors_and_segments_show_the_edit_cursors`, engine `tests::quickpen` (`a_drag_on_an_anchor_moves_it_and_the_arc_stays_an_arc`, `a_drag_on_a_segment_moves_its_ends`, `a_drag_on_an_open_end_moves_it`, `clicks_select_anchors_for_delete`, `escape_takes_back_an_anchor_drag`, `a_press_while_drawing_adds_a_piece`), ui-egui `tests::contextmenu::the_quick_pen_menu_deletes_the_selected_anchors`. Score and hours unchanged. - **Quick Pen tool (#2660, in part):** a tool in the Pen tool's group (Alt+P, Option+P on macOS) draws straight lines, continuous arcs and sharp-corner arcs, one undo step per piece; Alt pressed and let go on its own switches the action, C flips the last sharp-corner arc, `[` and `]` change the arc size by 15°, a click on the first point closes the path, a click on an open end continues it, and Escape or Enter ends it (`path.quickPen`), as [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) and [Quick Pen tool keyboard shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html) describe. The 180° default arc, its 15° steps, the side an arc bulges to, a dragged piece ending where the press is let go, and C, `[` and `]` changing the arc being dragged are VectorCraft's own rules. Tests: tools `quickpen::tests`, engine `tests::quickpen`, ui-egui `shortcuts::alt_tap::tests`, `alt_p_chooses_the_quick_pen_and_an_alt_tap_switches_its_action` and `brackets_size_the_quick_pen_arc_being_dragged`. Score and hours unchanged. - **Optional compact Tools (#7234):** Window > Toolbars > Compact Tools reduces row and column spacing and the main panel's allocated width in one or two columns, docked or floating. The setting is saved with the UI state and applies to Basic, Advanced and edited main Tools layouts; the selected tool, icon size, footer controls and tool-flyout behavior are retained. Turning it off restores the existing layout, which remains the default. Named custom toolbars and flyout spacing are unchanged. Public regressions in `crates/ui-egui/tests/toolbar_compact.rs` cover the actual toolbar layout against the default control, the command and saved-state roundtrip, tool selection, flyouts, footer controls and short-window reachability. This is an optional layout choice, without a styling-parity or score claim; hours are unchanged. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 911f08d192..7122033e47 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -205,7 +205,7 @@ tools, never checked side by side) isn't captured row by row. | Busy cursor during long operations | done | Background open, save and export show the system progress cursor (gap G1) | | Each anchor snaps to Smart Guides and construction angles | done | `DrawSnap` | | Curvature tool: click/drag points, double-click or Alt-click for a corner, temporary Direct Selection, point conversion | partial | circular point markers without direction handles or duplicate markers, Anchor Size and Hide Edges regression-tested (#1236, in part); curve geometry: each stretch of three points follows the circle through them (handles along its tangent, chord/(3·cos²(α/2)) long, shorter in a turn tighter than 30°), open ends curving in, the same rule for the rubber band, dragged, inserted and converted points (#1236, in part); neighbours of a point dragged on an existing path keep their tangents, and modifiers requested in #975 remain | -| Quick Pen tool: straight lines, continuous arcs and sharp-corner arcs, Alt/Option to switch action, C to flip an arc, `[` / `]` for its size, Alt+P / Option+P, close on the first point, continue from an end, Escape to end ([help page](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html), [shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html)) | partial | `path.quickPen` and the tool in `crates/tools/src/quickpen.rs`, in the Pen tool's group (#2660); the on-canvas toolbar with its actions, Flip Arc and its More menu (Hide Toolbar and Reset Toolbar Position, and VectorCraft's own Pin Toolbar Position) in `crates/ui-egui/src/canvas/quick_pen_bar.rs`. Not yet: dragging a path's ends to change a line's or arc's length, Ctrl+scroll for the arc size, and editing and deleting with the tool | +| Quick Pen tool: straight lines, continuous arcs and sharp-corner arcs, Alt/Option to switch action, C to flip an arc, `[` / `]` for its size, Alt+P / Option+P, close on the first point, continue from an end, Escape to end, drag anchors or segments to edit, right-click Delete ([help page](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html), [shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html)) | partial | `path.quickPen` and the tool in `crates/tools/src/quickpen.rs`, in the Pen tool's group (#2660); the on-canvas toolbar with its actions, Flip Arc and its More menu (Hide Toolbar and Reset Toolbar Position, and VectorCraft's own Pin Toolbar Position) in `crates/ui-egui/src/canvas/quick_pen_bar.rs`; with no path being drawn, drags on a selected path's anchors and segments move them (`quickpen/edit.rs`, `path.moveAnchors`), clicks select anchors, and the canvas context menu has Delete (`edit.clear`). Not yet: dragging a path's ends to change a line's or arc's length, and Ctrl+scroll for the arc size | | Icon-strip flyout resizing (#5713) | done | Canvas-side edge and bottom; user size persists after reopening and workspace restore; Glyphs and Artboards pointer/cursor regression | | Icon-strip flyout resizing from the top (storytold/craft-libs#1094) | done | Top edge (a 4 pt band over the tab strip) and the canvas-side top corner; the bottom and the icon-column edge stay; the moved top persists after reopening and workspace restore; `an_icon_flyout_grows_upward_from_its_top_edge_and_free_corner` | | Graphic Styles list fills a taller panel (#2992) | done | Docked, floating or in a resized flyout, the list takes the height above the panel's footer, as the Artboards list does; outside a sized panel it stays 220 pt; `the_list_fills_a_tall_panel_above_its_footer` | From 78d2a634ddb7d6a459d7e15a9e8bf22d591af38d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 19:22:33 -0800 Subject: [PATCH 2/9] Quick Pen: a press let go past the drag distance moves the anchor A press on an anchor or a segment of a selected path that is let go past the drag distance now moves what it holds, even when every drag event before the release stayed short. Before, such a release selected the anchor, or on an open end went on drawing from it. A press whose path another command edited while it was down does not move anything. The docs now say that a line stays a line and an arc stays circular beside a moved corner anchor, and that at a moved smooth anchor the handles stay in line and the segments bend to meet. --- ROADMAP.md | 2 +- crates/engine/src/tests/quickpen.rs | 40 +++++++++++++++++++++++++++++ crates/tools/src/quickpen.rs | 18 ++++++++----- crates/tools/src/quickpen/edit.rs | 21 ++++++++++++--- docs/mcp.md | 5 ++-- docs/target-app-parity.md | 2 +- 6 files changed, 73 insertions(+), 15 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 7c7bc4cd7c..b44607adf0 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -149,7 +149,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap - 2026-11-17: Circle Tool Options (double-click the Circle tool): Show Center, Show Radii and Show Diameter switch what the tool shows while a circle is drawn, Color sets the color of the center cross and radius lines, Anchors at Standard Positions off puts the circle's anchors at the points it was drawn through (`shape.circleThroughPoints {anchors: "points"}`), and Third Point by Dragging off draws a three-point circle with three clicks and a two-point circle with a double-click on the second point. A VectorCraft addition: headline numbers unchanged. - 2026-11-19: Quick Pen tool, in the Pen tool's group (Alt+P, Option+P on macOS): clicks or drags add straight lines, continuous arcs or sharp-corner arcs; Alt tapped on its own switches the action, C flips the last arc, `[` and `]` size it, a click on the first point closes the path and a click on an open end continues it (`path.quickPen`, part of #2660). Headline numbers unchanged. - 2026-11-19: Quick Pen toolbar on the canvas while the tool is active: Straight Line, Continuous Arc and Sharp Corner Arc, Flip Arc, and More Options with Hide Toolbar, Pin Toolbar Position and Reset Toolbar Position; it follows the drawing beside the path's last point and its handle drags it (`tool.quickPen.flipArc`, `window.quickPenToolbar`, Window › Quick Pen Toolbar; part of #2660). Headline numbers unchanged. -- 2026-11-19: Quick Pen editing: with no path being drawn, a drag on an anchor or a segment of a selected path moves it, a line staying a line and an arc an arc; a click selects an anchor, Shift-click adds one, and the canvas context menu's Delete removes the selected anchors (`path.moveAnchors`, `edit.clear`; #2660). Headline numbers unchanged. +- 2026-11-19: Quick Pen editing: with no path being drawn, a drag on an anchor or a segment of a selected path moves it, a line staying a line and an arc an arc beside a moved corner anchor (at a smooth anchor the handles stay in line and the segments bend to meet); a click selects an anchor, Shift-click adds one, and the canvas context menu's Delete removes the selected anchors (`path.moveAnchors`, `edit.clear`; #2660). Headline numbers unchanged. - 2026-10-31: Pattern libraries: Window › Swatch Libraries › Patterns and the Swatches panel's library menu open Geometric Patterns, a built-in library of eleven pattern swatches (dots, stripes, checks, a grid and shapes); clicking one adds its pattern and swatch to the document, once, and applies it to the active fill or stroke (`swatch.library.add`). - 2026-11-11: Pattern libraries: Patterns › Grit Textures, a second built-in pattern library, holds eight seamless black textures (Fine Grain, Coarse Grit, Sand, Speckle, Stipple, Scratches, Sparse Flecks and Dense Flecks) on tiles of 18 to 36 pt, each drawn the same way every time; marks that reach past a tile edge continue on the next tile, so the tiles join without a seam (`swatch.library.add`). Scores and estimates unchanged. - 2026-11-11: Pattern libraries: Patterns › Optical Effects, a third built-in pattern library, of VectorCraft's own designs, holds eight black wave, moiré and op-art tiles (Sine Bands, Ripple Lines, Interference Rings, Offset Rings, Warped Checks, Pinched Stripes, Chevron Pulse and Radiating Lenses) of 32 to 48 pt, each drawn the same way every time; each tile is one period of its design, and art that reaches past a tile edge continues on the next tile, so the tiles join without a seam (`swatch.library.add`). Scores and estimates unchanged. diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index 5f41ecedb7..c09fc797d4 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -644,6 +644,46 @@ fn a_drag_on_an_open_end_moves_it() { assert_eq!(points(&s), [pt(100.0, 300.0), pt(350.0, 350.0), pt(350.0, 450.0)]); } +/// A press let go past the drag distance moves what it holds even when no drag event went that +/// far: an inner anchor moves, and an open end moves instead of going on drawing. +#[test] +fn a_release_past_the_drag_distance_moves_the_anchor() { + let mut s = session(); + selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let undo = undo_steps(&s); + let v = view(); + s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 100.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 102.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 150.0), v).unwrap(); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 150.0), pt(300.0, 100.0)]); + assert_eq!(undo_steps(&s), undo + 1); + s.pointer(&PointerEvent::new(PointerKind::Down, 300.0, 100.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, 300.0, 200.0), v).unwrap(); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 150.0), pt(300.0, 200.0)]); + assert_eq!(undo_steps(&s), undo + 2); + assert_eq!(paths(&s).len(), 1, "no new path"); +} + +/// When another command edits the path while the press is down, neither a drag nor a release past +/// the drag distance moves the anchor the press found. +#[test] +fn an_edit_during_an_edit_press_stops_the_move() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let v = view(); + for (drag, x) in [(true, 90.0), (false, 80.0)] { + s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 100.0), v).unwrap(); + s.execute("path.moveAnchor", &json!({"id": id.0, "anchor": 0, "x": x, "y": 90})).unwrap(); + let undo = undo_steps(&s); + if drag { + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 150.0), v).unwrap(); + } + s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 150.0), v).unwrap(); + assert_eq!(points(&s), [pt(x, 90.0), pt(200.0, 100.0), pt(300.0, 100.0)], "drag: {drag}"); + assert_eq!(undo_steps(&s), undo, "drag: {drag}"); + } +} + /// A click on an anchor selects it alone, Shift-click adds another, and Delete (`edit.clear`, the /// context menu's Delete) then removes both. #[test] diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index 290c0f494a..a8fd4c4fb7 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -450,7 +450,7 @@ impl QuickPenTool { return vec![Action::Begin("Quick Pen".into()), Action::Preview(COMMAND.into(), self.params(false)), drawn()]; } if let Some(grab) = edit::grab_at(cx, p, tol) { - self.edit = Some(Edit::new(grab, p, shift)); + self.edit = Some(Edit::new(cx, grab, p, shift)); return vec![]; } if let Some((id, si, at_first)) = open_end_at(cx, p, tol, None) @@ -496,14 +496,18 @@ impl QuickPenTool { } } - /// The release of a press on an anchor or a segment of a selected path: a drag moves what it - /// holds to `p` and ends its undo step. A click on an end of an open path goes on drawing from - /// it, a click on another anchor selects it alone (with Shift, adds it to the selected anchors - /// or takes it out), and a click on a segment starts a new path there. + /// The release of a press on an anchor or a segment of a selected path: a drag, also one let + /// go past the drag distance after shorter drag events, moves what it holds to `p` and ends + /// its undo step. A click on an end of an open path goes on drawing from it, a click on another + /// anchor selects it alone (with Shift, adds it to the selected anchors or takes it out), and a + /// click on a segment starts a new path there. fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { - if e.began { + if e.began || p.distance(e.start) >= cx.tol(DRAG_PX) { let mut out = e.drag(cx, p); - out.push(Action::Commit); + // A drag that could not begin (its path changed under the press) has no step to end. + if e.began { + out.push(Action::Commit); + } return out; } match e.grab { diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index ee219a8d63..918db28ad9 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -8,11 +8,13 @@ //! of an open path goes on drawing from it, as before. use std::collections::BTreeSet; +use std::sync::Arc; use serde_json::json; -use vectorcraft_doc::{AnchorRef, NodeId, Selection}; +use vectorcraft_doc::{AnchorRef, Node, NodeId, Selection}; use vectorcraft_geom::Point; +use super::{same_node, shared_node}; use crate::draw2::{anchor_in, segment_in, shown_paths}; use crate::guides::{PointSnap, Targets}; use crate::{Action, Cursor, Overlay, ToolContext}; @@ -79,22 +81,33 @@ pub(super) struct Edit { pub(super) shift: bool, /// Whether the press has dragged far enough to move what it holds (an undo step began). pub(super) began: bool, + /// The grabbed path as the document had it when the press went down. + pressed: Option>, snap: Option, pub(super) guides: Vec, } impl Edit { - pub(super) fn new(grab: Grab, start: Point, shift: bool) -> Self { - Self { grab, start, shift, began: false, snap: None, guides: vec![] } + pub(super) fn new(cx: &ToolContext, grab: Grab, start: Point, shift: bool) -> Self { + let pressed = shared_node(cx.doc, grab.id()).cloned(); + Self { grab, start, shift, began: false, pressed, snap: None, guides: vec![] } } /// Moves what the press holds by the drag to `p`. The first move selects the anchor, or the /// segment, unless it is already selected, and begins the undo step; a drag that starts on - /// one of several selected anchors moves them all. + /// one of several selected anchors moves them all. When the grabbed path changed after the + /// press went down, the drag does not begin. pub(super) fn drag(&mut self, cx: &ToolContext, p: Point) -> Vec { let mut out = vec![]; if !self.began { let id = self.grab.id(); + let unchanged = match (cx.doc.node(id), self.pressed.as_ref()) { + (Some(now), Some(then)) => same_node(now, then), + _ => false, + }; + if !unchanged { + return out; + } let Some(picked) = self.grab.anchors(cx) else { return out }; let already = cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a))); let moving = if already { diff --git a/docs/mcp.md b/docs/mcp.md index add7833de6..d91a32e569 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7344,8 +7344,9 @@ With no path being drawn (after Escape or Enter, or before the first click), the describes. A drag on one of their anchors moves that anchor, and a drag that starts on one of several selected anchors moves them all; a drag on a segment moves that segment's two ends. The tool selects what it moves (`select.anchors` or `select.segments` with `mode: "set"`) and moves it with `path.moveAnchors {dx, dy, interpolate: -true}`, one undo step per drag: a segment with one moved end is turned and scaled to its new ends, so a line stays a -line and an arc stays an arc through the same angle, and at a smooth point the handles stay in line. A dragged anchor +true}`, one undo step per drag: a segment with one moved end is turned and scaled to its new ends, so beside a corner +anchor a line stays a line and an arc stays an arc through the same angle; at a smooth anchor the handles stay in line +and the segments bend to meet, so an arc there need not stay circular. A dragged anchor snaps to Smart Guides; a dragged segment does not. Escape during the drag takes it back. A click on an anchor selects it alone and Shift-click adds it to the selected anchors or takes it out (`select.anchors` with `"set"` or `"toggle"`). A click on an end of an open path still goes on drawing from it, a drag there moves the end, and a click diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 5058e1f6df..d400f52ec4 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -634,7 +634,7 @@ since 2026-10-01. - **Trim View hides guides and the grid (#8363):** while View › Trim View is on, the canvas and tiled panes draw no ruler guides, no guide paths and no grid, the guides are neither snapped to nor picked, and Show/Hide Guides and Show/Hide Grid are greyed out (menu bar, canvas context menu, Properties) and refuse to run; the stored choices come back when it is turned off, and the rulers stay ([trim view hides guides](https://community.adobe.com/t5/illustrator-discussions/trim-view-hides-guides/td-p/14066140), [guides greyed out](https://community.adobe.com/t5/illustrator-discussions/guides-greyed-out/m-p/11132728)). A drag or double-click on a ruler makes no guide while it is on (no preview, no undo step, a status message). `trim_view_hides_the_guides_and_the_grid`, `trim_view_deselects_selected_guide_paths`, `trim_view_makes_no_guide_from_the_rulers` in `crates/ui-egui/src/canvas/tests.rs`; `trim_view_greys_out_show_guides_and_show_grid` in `crates/ui-egui/src/menus/tests.rs`. - **Recolor picker follow-up (#8031/#4028):** native Lab numeric entry, document/loaded-library swatches in the Color Picker, and Assign-row Pick from Swatches / Limit to Library menus. #4090 provided the double-click picker and #5113 the Assign sliders. Regression tests `native_lab_entry_in_color_picker` and `row_context_menu_pick_from_swatches_and_limit_to_library` exercise the fields and menu callbacks rather than writing their result state. Area score and hours unchanged. -- **Quick Pen editing (#2660):** with no path being drawn, the Quick Pen tool moves an anchor or a segment of a selected path by a drag (`path.moveAnchors` with `interpolate`, one undo step, a line staying a line and an arc an arc), selects an anchor with a click and adds one with Shift-click, and the canvas context menu's Delete removes the selected anchors (`edit.clear`), as [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) describes. Which presses select and which move, and the drag snapping only an anchor, are VectorCraft's own rules. Tests: tools `quickpen::tests::a_selected_paths_anchors_and_segments_show_the_edit_cursors`, engine `tests::quickpen` (`a_drag_on_an_anchor_moves_it_and_the_arc_stays_an_arc`, `a_drag_on_a_segment_moves_its_ends`, `a_drag_on_an_open_end_moves_it`, `clicks_select_anchors_for_delete`, `escape_takes_back_an_anchor_drag`, `a_press_while_drawing_adds_a_piece`), ui-egui `tests::contextmenu::the_quick_pen_menu_deletes_the_selected_anchors`. Score and hours unchanged. +- **Quick Pen editing (#2660):** with no path being drawn, the Quick Pen tool moves an anchor or a segment of a selected path by a drag (`path.moveAnchors` with `interpolate`, one undo step; beside a moved corner anchor a line stays a line and an arc an arc, and at a moved smooth anchor the handles stay in line and the segments bend to meet), selects an anchor with a click and adds one with Shift-click, and the canvas context menu's Delete removes the selected anchors (`edit.clear`), as [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) describes. Which presses select and which move, and the drag snapping only an anchor, are VectorCraft's own rules. Tests: tools `quickpen::tests::a_selected_paths_anchors_and_segments_show_the_edit_cursors`, engine `tests::quickpen` (`a_drag_on_an_anchor_moves_it_and_the_arc_stays_an_arc`, `a_drag_on_a_segment_moves_its_ends`, `a_drag_on_an_open_end_moves_it`, `a_release_past_the_drag_distance_moves_the_anchor`, `clicks_select_anchors_for_delete`, `escape_takes_back_an_anchor_drag`, `a_press_while_drawing_adds_a_piece`), ui-egui `tests::contextmenu::the_quick_pen_menu_deletes_the_selected_anchors`. Score and hours unchanged. - **Quick Pen tool (#2660, in part):** a tool in the Pen tool's group (Alt+P, Option+P on macOS) draws straight lines, continuous arcs and sharp-corner arcs, one undo step per piece; Alt pressed and let go on its own switches the action, C flips the last sharp-corner arc, `[` and `]` change the arc size by 15°, a click on the first point closes the path, a click on an open end continues it, and Escape or Enter ends it (`path.quickPen`), as [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) and [Quick Pen tool keyboard shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html) describe. The 180° default arc, its 15° steps, the side an arc bulges to, a dragged piece ending where the press is let go, and C, `[` and `]` changing the arc being dragged are VectorCraft's own rules. Tests: tools `quickpen::tests`, engine `tests::quickpen`, ui-egui `shortcuts::alt_tap::tests`, `alt_p_chooses_the_quick_pen_and_an_alt_tap_switches_its_action` and `brackets_size_the_quick_pen_arc_being_dragged`. Score and hours unchanged. - **Optional compact Tools (#7234):** Window > Toolbars > Compact Tools reduces row and column spacing and the main panel's allocated width in one or two columns, docked or floating. The setting is saved with the UI state and applies to Basic, Advanced and edited main Tools layouts; the selected tool, icon size, footer controls and tool-flyout behavior are retained. Turning it off restores the existing layout, which remains the default. Named custom toolbars and flyout spacing are unchanged. Public regressions in `crates/ui-egui/tests/toolbar_compact.rs` cover the actual toolbar layout against the default control, the command and saved-state roundtrip, tool selection, flyouts, footer controls and short-window reachability. This is an optional layout choice, without a styling-parity or score claim; hours are unchanged. From 17a1a5543f79156528ddb47bcd32edff6eb19b19 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 20:01:41 -0800 Subject: [PATCH 3/9] Quick Pen: a first Shift-click selects one anchor; a segment drag moves its ends A first Shift-click on an anchor of a path selected whole now selects that anchor alone. Before, it selected every other anchor of the path. A drag on a segment now moves only that segment's two ends. Before, when both ends were selected together with other anchors, the drag moved the other anchors too. --- crates/engine/src/tests/quickpen.rs | 27 +++++++++++++++++++++++++++ crates/tools/src/quickpen.rs | 6 +++++- crates/tools/src/quickpen/edit.rs | 11 ++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index c09fc797d4..d3746d3c8e 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -705,6 +705,33 @@ fn clicks_select_anchors_for_delete() { assert!(!left.contains(&pt(200.0, 100.0)) && !left.contains(&pt(300.0, 100.0)), "{left:?}"); } +/// The first Shift-click on an anchor of a path selected whole selects that anchor alone. +#[test] +fn a_first_shift_click_selects_the_anchor_alone() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + assert!(s.doc().unwrap().selection.partial(id).is_none(), "the path is selected whole"); + shift_click(&mut s, 200.0, 100.0); + let picked = s.doc().unwrap().selection.partial(id).cloned().unwrap_or_default().into_iter().collect::>(); + assert_eq!(picked, [(0, 1)]); +} + +/// A drag on a segment moves its two ends alone, also when they are selected with another anchor. +#[test] +fn a_segment_drag_moves_only_its_ends() { + let mut s = session(); + let pieces = json!([{"x": 300, "y": 300}, {"x": 300, "y": 400}, {"x": 100, "y": 400}, {"x": 100, "y": 500}]); + let id = selected_quick_pen_path(&mut s, (100.0, 300.0), pieces); + click(&mut s, 300.0, 300.0); + shift_click(&mut s, 300.0, 400.0); + shift_click(&mut s, 100.0, 400.0); + let picked = s.doc().unwrap().selection.partial(id).cloned().unwrap_or_default().into_iter().collect::>(); + assert_eq!(picked, [(0, 1), (0, 2), (0, 3)]); + press(&mut s, &[(300.0, 350.0), (320.0, 350.0), (350.0, 350.0)]); + assert_eq!(points(&s), [pt(100.0, 300.0), pt(350.0, 300.0), pt(350.0, 400.0), pt(100.0, 400.0), pt(100.0, 500.0)]); + assert_eq!(paths(&s).len(), 1); +} + /// Escape during a drag puts the anchor back, and the release then changes nothing. #[test] fn escape_takes_back_an_anchor_drag() { diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index a8fd4c4fb7..f76cf806bf 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -512,7 +512,11 @@ impl QuickPenTool { } match e.grab { Grab::Anchor { id, si, ai, .. } if e.shift => { - vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "toggle"}))] + // `select.anchors` toggles from every anchor of a path selected whole on its own, + // so the first Shift-click there selects the anchor alone. + let whole = cx.selection.anchors.is_empty() && cx.selection.objects.len() <= 1; + let mode = if whole { "set" } else { "toggle" }; + vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": mode}))] } Grab::Anchor { id, si, ai, end: true, .. } => self.continue_path(cx, id, si, ai == 0), Grab::Anchor { id, si, ai, .. } => { diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index 918db28ad9..3e1e0509a7 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -109,7 +109,16 @@ impl Edit { return out; } let Some(picked) = self.grab.anchors(cx) else { return out }; - let already = cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a))); + // A drag on one of several selected anchors moves them all; a drag on a segment moves + // its two ends alone. + let already = match self.grab { + Grab::Anchor { .. } => cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a))), + Grab::Segment { .. } => { + cx.selection.objects == [id] + && cx.selection.anchors.len() == 1 + && cx.selection.partial(id).is_some_and(|s| s.len() == picked.len() && picked.iter().all(|a| s.contains(a))) + } + }; let moving = if already { cx.selection.clone() } else { From ec1888430876428c15c42a224ed4560f1dd09197 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 20:24:16 -0800 Subject: [PATCH 4/9] Quick Pen: a click on a path edited during the press does nothing When another command edits the path while a click on one of its anchors is down, the release no longer selects an anchor or goes on drawing from the open end the press found. Before, the click used the anchor index and the end it had stored before the edit. --- crates/engine/src/tests/quickpen.rs | 18 ++++++++++++++++++ crates/tools/src/quickpen.rs | 6 +++++- crates/tools/src/quickpen/edit.rs | 14 +++++++++----- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index d3746d3c8e..412406c80a 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -684,6 +684,24 @@ fn an_edit_during_an_edit_press_stops_the_move() { } } +/// When another command edits the path while a click is down, the click neither selects the +/// anchor nor goes on drawing from the open end it found. +#[test] +fn an_edit_during_an_edit_click_does_nothing() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let v = view(); + for (x, moved_y) in [(200.0, 90.0), (300.0, 80.0)] { + s.pointer(&PointerEvent::new(PointerKind::Down, x, 100.0), v).unwrap(); + s.execute("path.moveAnchor", &json!({"id": id.0, "anchor": 0, "x": 100, "y": moved_y})).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, x, 100.0), v).unwrap(); + assert!(s.doc().unwrap().selection.partial(id).is_none(), "no anchor selected after a click at x = {x}"); + } + // The open end was not taken up, so the next click starts a new path. + click(&mut s, 400.0, 200.0); + assert_eq!(paths(&s).len(), 2); +} + /// A click on an anchor selects it alone, Shift-click adds another, and Delete (`edit.clear`, the /// context menu's Delete) then removes both. #[test] diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index f76cf806bf..c3188250fb 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -500,7 +500,8 @@ impl QuickPenTool { /// go past the drag distance after shorter drag events, moves what it holds to `p` and ends /// its undo step. A click on an end of an open path goes on drawing from it, a click on another /// anchor selects it alone (with Shift, adds it to the selected anchors or takes it out), and a - /// click on a segment starts a new path there. + /// click on a segment starts a new path there. A click whose path another command edited while + /// the press was down does nothing. fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { if e.began || p.distance(e.start) >= cx.tol(DRAG_PX) { let mut out = e.drag(cx, p); @@ -510,6 +511,9 @@ impl QuickPenTool { } return out; } + if !e.unchanged(cx) { + return vec![]; + } match e.grab { Grab::Anchor { id, si, ai, .. } if e.shift => { // `select.anchors` toggles from every anchor of a path selected whole on its own, diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index 3e1e0509a7..a7d5f6de55 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -93,6 +93,14 @@ impl Edit { Self { grab, start, shift, began: false, pressed, snap: None, guides: vec![] } } + /// Whether the grabbed path is as the document had it when the press went down. + pub(super) fn unchanged(&self, cx: &ToolContext) -> bool { + match (cx.doc.node(self.grab.id()), self.pressed.as_ref()) { + (Some(now), Some(then)) => same_node(now, then), + _ => false, + } + } + /// Moves what the press holds by the drag to `p`. The first move selects the anchor, or the /// segment, unless it is already selected, and begins the undo step; a drag that starts on /// one of several selected anchors moves them all. When the grabbed path changed after the @@ -101,11 +109,7 @@ impl Edit { let mut out = vec![]; if !self.began { let id = self.grab.id(); - let unchanged = match (cx.doc.node(id), self.pressed.as_ref()) { - (Some(now), Some(then)) => same_node(now, then), - _ => false, - }; - if !unchanged { + if !self.unchanged(cx) { return out; } let Some(picked) = self.grab.anchors(cx) else { return out }; From 059628a14cfc685fda8b65cc451b9276499bf228 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 20:47:12 -0800 Subject: [PATCH 5/9] Quick Pen: a drag back to its start records no undo step A drag on an anchor or a segment that is let go where it started now moves nothing and adds no undo step. Before, it recorded a Move step that changed nothing. --- crates/engine/src/tests/quickpen.rs | 14 ++++++++++++++ crates/tools/src/quickpen.rs | 5 +++-- crates/tools/src/quickpen/edit.rs | 5 ++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index 412406c80a..b1142eff1f 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -664,6 +664,20 @@ fn a_release_past_the_drag_distance_moves_the_anchor() { assert_eq!(paths(&s).len(), 1, "no new path"); } +/// A drag on an anchor or a segment that comes back to where it started moves nothing and records +/// no undo step. +#[test] +fn a_drag_back_to_its_start_records_no_undo_step() { + let mut s = session(); + selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let undo = undo_steps(&s); + for at in [(200.0, 100.0), (250.0, 100.0)] { + press(&mut s, &[at, (at.0, at.1 + 50.0), at]); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 100.0), pt(300.0, 100.0)], "press at {at:?}"); + assert_eq!(undo_steps(&s), undo, "press at {at:?}"); + } +} + /// When another command edits the path while the press is down, neither a drag nor a release past /// the drag distance moves the anchor the press found. #[test] diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index c3188250fb..106f320e49 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -505,9 +505,10 @@ impl QuickPenTool { fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { if e.began || p.distance(e.start) >= cx.tol(DRAG_PX) { let mut out = e.drag(cx, p); - // A drag that could not begin (its path changed under the press) has no step to end. + // A drag that could not begin (its path changed under the press) has no step to end, + // and one that came back to where it started records none. if e.began { - out.push(Action::Commit); + out.push(if e.moved { Action::Commit } else { Action::Cancel }); } return out; } diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index a7d5f6de55..be23386268 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -81,6 +81,8 @@ pub(super) struct Edit { pub(super) shift: bool, /// Whether the press has dragged far enough to move what it holds (an undo step began). pub(super) began: bool, + /// Whether the last drag left what the press holds away from where it started. + pub(super) moved: bool, /// The grabbed path as the document had it when the press went down. pressed: Option>, snap: Option, @@ -90,7 +92,7 @@ pub(super) struct Edit { impl Edit { pub(super) fn new(cx: &ToolContext, grab: Grab, start: Point, shift: bool) -> Self { let pressed = shared_node(cx.doc, grab.id()).cloned(); - Self { grab, start, shift, began: false, pressed, snap: None, guides: vec![] } + Self { grab, start, shift, began: false, moved: false, pressed, snap: None, guides: vec![] } } /// Whether the grabbed path is as the document had it when the press went down. @@ -154,6 +156,7 @@ impl Edit { if !d.x.is_finite() || !d.y.is_finite() { return out; } + self.moved = d.x != 0.0 || d.y != 0.0; out.push(Action::Preview("path.moveAnchors".into(), json!({"dx": d.x, "dy": d.y, "interpolate": true}))); out } From 1410f7500c203b280308dc89606351634dd72d18 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 21:23:36 -0800 Subject: [PATCH 6/9] Quick Pen: an edit by another command during a drag stays When another command edits the document or the selection during a drag on an anchor or a segment, the drag now previews no more and its undo step keeps that edit with the move as last shown, also when Escape ends the drag. Before, the next drag event previewed from the document as it was before the edit, so the edit was lost. --- crates/engine/src/tests/quickpen.rs | 26 +++++++++++++++++++++++ crates/tools/src/quickpen.rs | 24 +++++++++++++-------- crates/tools/src/quickpen/edit.rs | 33 +++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index b1142eff1f..39cc07a530 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -698,6 +698,32 @@ fn an_edit_during_an_edit_press_stops_the_move() { } } +/// An edit made by another command during an anchor drag stays: the rest of the drag and the +/// release move nothing more, and one undo step holds the move as last shown with the edit. +#[test] +fn an_edit_during_an_anchor_drag_stays() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let undo = undo_steps(&s); + let v = view(); + s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 100.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 150.0), v).unwrap(); + s.execute("path.moveAnchor", &json!({"id": id.0, "anchor": 0, "x": 90, "y": 90})).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 200.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 210.0), v).unwrap(); + assert_eq!(points(&s), [pt(90.0, 90.0), pt(200.0, 150.0), pt(300.0, 100.0)], "the edit and the move as last shown"); + assert_eq!(undo_steps(&s), undo + 1); + assert!(!s.in_interaction(), "the step is committed"); + // Escape after such an edit keeps it too. + s.pointer(&PointerEvent::new(PointerKind::Down, 300.0, 100.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 300.0, 150.0), v).unwrap(); + s.execute("path.moveAnchor", &json!({"id": id.0, "anchor": 0, "x": 80, "y": 80})).unwrap(); + key(&mut s, ToolKey::Escape); + s.pointer(&PointerEvent::new(PointerKind::Up, 300.0, 200.0), v).unwrap(); + assert_eq!(points(&s), [pt(80.0, 80.0), pt(200.0, 150.0), pt(300.0, 150.0)]); + assert!(!s.in_interaction(), "the step is committed"); +} + /// When another command edits the path while a click is down, the click neither selects the /// anchor nor goes on drawing from the open end it found. #[test] diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index 106f320e49..bdb80c2a5b 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -484,15 +484,14 @@ impl QuickPenTool { } /// Ends the path being drawn; a press that added a piece, or moved part of a path, is taken - /// back. - fn end(&mut self) -> Vec { + /// back. A move that another command's edit interrupted is kept with that edit. + fn end(&mut self, cx: &ToolContext) -> Vec { self.drawing = None; self.snap.clear(); - let moved = self.edit.take().is_some_and(|e| e.began); + let moved = self.edit.take().filter(|e| e.began).map(|mut e| if e.open(cx) { Action::Cancel } else { Action::Commit }); match self.press.take() { Some(pr) if pr.begun => vec![Action::Cancel], - _ if moved => vec![Action::Cancel], - _ => vec![], + _ => moved.into_iter().collect(), } } @@ -505,10 +504,11 @@ impl QuickPenTool { fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { if e.began || p.distance(e.start) >= cx.tol(DRAG_PX) { let mut out = e.drag(cx, p); - // A drag that could not begin (its path changed under the press) has no step to end, - // and one that came back to where it started records none. + // A drag that could not begin (its path changed under the press) has no step to end. + // One that came back to where it started records none, unless another command's + // edit during the drag is in the step. if e.began { - out.push(if e.moved { Action::Commit } else { Action::Cancel }); + out.push(if e.moved || e.interrupted { Action::Commit } else { Action::Cancel }); } return out; } @@ -622,6 +622,12 @@ impl Tool for QuickPenTool { } fn notify(&mut self, cx: &ToolContext, what: &str) { + if what == edit::MOVED { + if let Some(e) = self.edit.as_mut() { + e.revision = Some(cx.revision); + } + return; + } let Some(dr) = self.drawing.as_mut() else { return }; if what == "created" && let [id] = cx.selection.objects.as_slice() @@ -686,7 +692,7 @@ impl Tool for QuickPenTool { fn key(&mut self, cx: &ToolContext, key: ToolKey, _mods: Mods) -> Vec { match key { - ToolKey::Escape | ToolKey::Enter => self.end(), + ToolKey::Escape | ToolKey::Enter => self.end(cx), ToolKey::Letter('c') => { if self.last_sharp_arc(cx).is_none() { return vec![]; diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index be23386268..8ba8f970ce 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -19,6 +19,9 @@ use crate::draw2::{anchor_in, segment_in, shown_paths}; use crate::guides::{PointSnap, Targets}; use crate::{Action, Cursor, Overlay, ToolContext}; +/// The notice the tool asks for after each preview of a drag, to see the document's revision then. +pub(super) const MOVED: &str = "moved"; + /// What a press holds. #[derive(Clone, Copy, Debug, PartialEq)] pub(super) enum Grab { @@ -83,6 +86,11 @@ pub(super) struct Edit { pub(super) began: bool, /// Whether the last drag left what the press holds away from where it started. pub(super) moved: bool, + /// The document's revision ([`ToolContext::revision`]) after the drag's last preview. + pub(super) revision: Option<(u64, u64)>, + /// Whether another command changed the document or the selection during the drag: the drag + /// then previews no more, and its undo step keeps that edit with the move as last shown. + pub(super) interrupted: bool, /// The grabbed path as the document had it when the press went down. pressed: Option>, snap: Option, @@ -92,7 +100,16 @@ pub(super) struct Edit { impl Edit { pub(super) fn new(cx: &ToolContext, grab: Grab, start: Point, shift: bool) -> Self { let pressed = shared_node(cx.doc, grab.id()).cloned(); - Self { grab, start, shift, began: false, moved: false, pressed, snap: None, guides: vec![] } + Self { grab, start, shift, began: false, moved: false, revision: None, interrupted: false, pressed, snap: None, guides: vec![] } + } + + /// Whether the drag began and still previews: no other command changed the document or the + /// selection since its last preview. + pub(super) fn open(&mut self, cx: &ToolContext) -> bool { + if self.began && self.revision.is_some_and(|r| r != cx.revision) { + self.interrupted = true; + } + self.began && !self.interrupted } /// Whether the grabbed path is as the document had it when the press went down. @@ -106,9 +123,13 @@ impl Edit { /// Moves what the press holds by the drag to `p`. The first move selects the anchor, or the /// segment, unless it is already selected, and begins the undo step; a drag that starts on /// one of several selected anchors moves them all. When the grabbed path changed after the - /// press went down, the drag does not begin. + /// press went down, the drag does not begin, and after another command's edit during the + /// drag it moves nothing more. pub(super) fn drag(&mut self, cx: &ToolContext, p: Point) -> Vec { let mut out = vec![]; + if self.began && !self.open(cx) { + return out; + } if !self.began { let id = self.grab.id(); if !self.unchanged(cx) { @@ -153,11 +174,11 @@ impl Edit { } _ => p - self.start, }; - if !d.x.is_finite() || !d.y.is_finite() { - return out; + if d.x.is_finite() && d.y.is_finite() { + self.moved = d.x != 0.0 || d.y != 0.0; + out.push(Action::Preview("path.moveAnchors".into(), json!({"dx": d.x, "dy": d.y, "interpolate": true}))); } - self.moved = d.x != 0.0 || d.y != 0.0; - out.push(Action::Preview("path.moveAnchors".into(), json!({"dx": d.x, "dy": d.y, "interpolate": true}))); + out.push(Action::Notify(MOVED.into())); out } } From 357133cef1bfeed76a808ba4ad5b78b138a0e564 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 21:51:20 -0800 Subject: [PATCH 7/9] Quick Pen: a selection change during a press stops it When another command changes the selection while a press on an anchor or a segment is down, the release no longer selects an anchor, goes on drawing from an open end, or moves anything. Choosing another tool during a drag that came back to where it started now records no undo step. --- crates/engine/src/tests/quickpen.rs | 31 ++++++++++++++++++++++++ crates/tools/src/quickpen.rs | 20 +++++++--------- crates/tools/src/quickpen/edit.rs | 37 ++++++++++++++++++++++++----- 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index 39cc07a530..e9181b03d7 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -676,6 +676,37 @@ fn a_drag_back_to_its_start_records_no_undo_step() { assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 100.0), pt(300.0, 100.0)], "press at {at:?}"); assert_eq!(undo_steps(&s), undo, "press at {at:?}"); } + // Choosing another tool during such a drag records none either. + let v = view(); + s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 100.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 150.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 100.0), v).unwrap(); + s.select_tool("selection", v).unwrap(); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 100.0), pt(300.0, 100.0)]); + assert_eq!(undo_steps(&s), undo); +} + +/// When another command changes the selection while the press is down, neither a click nor a drag +/// selects or moves the anchor the press found. +#[test] +fn a_selection_change_during_an_edit_press_stops_it() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let v = view(); + for drag in [false, true] { + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + let undo = undo_steps(&s); + s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 100.0), v).unwrap(); + s.execute("select.none", &json!({})).unwrap(); + let y = if drag { 150.0 } else { 100.0 }; + if drag { + s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, y), v).unwrap(); + } + s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, y), v).unwrap(); + assert!(s.doc().unwrap().selection.objects.is_empty(), "drag: {drag}"); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 100.0), pt(300.0, 100.0)], "drag: {drag}"); + assert_eq!(undo_steps(&s), undo, "drag: {drag}"); + } } /// When another command edits the path while the press is down, neither a drag nor a release past diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index bdb80c2a5b..62819f793f 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -499,17 +499,14 @@ impl QuickPenTool { /// go past the drag distance after shorter drag events, moves what it holds to `p` and ends /// its undo step. A click on an end of an open path goes on drawing from it, a click on another /// anchor selects it alone (with Shift, adds it to the selected anchors or takes it out), and a - /// click on a segment starts a new path there. A click whose path another command edited while - /// the press was down does nothing. + /// click on a segment starts a new path there. A click whose path or selection another command + /// changed while the press was down does nothing. fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { if e.began || p.distance(e.start) >= cx.tol(DRAG_PX) { let mut out = e.drag(cx, p); - // A drag that could not begin (its path changed under the press) has no step to end. - // One that came back to where it started records none, unless another command's - // edit during the drag is in the step. - if e.began { - out.push(if e.moved || e.interrupted { Action::Commit } else { Action::Cancel }); - } + // A drag that could not begin (its path or the selection changed under the press) has + // no step to end. + out.extend(e.finish(cx)); return out; } if !e.unchanged(cx) { @@ -734,14 +731,13 @@ impl Tool for QuickPenTool { } } - fn deactivate(&mut self, _cx: &ToolContext) -> Vec { + fn deactivate(&mut self, cx: &ToolContext) -> Vec { self.drawing = None; self.snap.clear(); - let moved = self.edit.take().is_some_and(|e| e.began); + let moved = self.edit.take().and_then(|mut e| e.finish(cx)); match self.press.take() { Some(pr) if pr.begun => vec![Action::Commit], - _ if moved => vec![Action::Commit], - _ => vec![], + _ => moved.into_iter().collect(), } } diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index 8ba8f970ce..2620118b91 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -93,6 +93,8 @@ pub(super) struct Edit { pub(super) interrupted: bool, /// The grabbed path as the document had it when the press went down. pressed: Option>, + /// The selection when the press went down. + pressed_selection: Selection, snap: Option, pub(super) guides: Vec, } @@ -100,7 +102,20 @@ pub(super) struct Edit { impl Edit { pub(super) fn new(cx: &ToolContext, grab: Grab, start: Point, shift: bool) -> Self { let pressed = shared_node(cx.doc, grab.id()).cloned(); - Self { grab, start, shift, began: false, moved: false, revision: None, interrupted: false, pressed, snap: None, guides: vec![] } + let pressed_selection = cx.selection.clone(); + Self { + grab, + start, + shift, + began: false, + moved: false, + revision: None, + interrupted: false, + pressed, + pressed_selection, + snap: None, + guides: vec![], + } } /// Whether the drag began and still previews: no other command changed the document or the @@ -112,18 +127,28 @@ impl Edit { self.began && !self.interrupted } - /// Whether the grabbed path is as the document had it when the press went down. + /// What ends a drag that began when the press is let go: a commit, or a cancel when the drag + /// came back to where it started and no other command's edit is in its undo step. + pub(super) fn finish(&mut self, cx: &ToolContext) -> Option { + if !self.began { + return None; + } + Some(if self.open(cx) && !self.moved { Action::Cancel } else { Action::Commit }) + } + + /// Whether the grabbed path and the selection are as they were when the press went down. pub(super) fn unchanged(&self, cx: &ToolContext) -> bool { - match (cx.doc.node(self.grab.id()), self.pressed.as_ref()) { + let path = match (cx.doc.node(self.grab.id()), self.pressed.as_ref()) { (Some(now), Some(then)) => same_node(now, then), _ => false, - } + }; + path && *cx.selection == self.pressed_selection } /// Moves what the press holds by the drag to `p`. The first move selects the anchor, or the /// segment, unless it is already selected, and begins the undo step; a drag that starts on - /// one of several selected anchors moves them all. When the grabbed path changed after the - /// press went down, the drag does not begin, and after another command's edit during the + /// one of several selected anchors moves them all. When the grabbed path or the selection + /// changed after the press went down, the drag does not begin, and after another command's edit during the /// drag it moves nothing more. pub(super) fn drag(&mut self, cx: &ToolContext, p: Point) -> Vec { let mut out = vec![]; From cb3946fe2f041f18e86de7e5be23d8be95f6345a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 22:23:15 -0800 Subject: [PATCH 8/9] Quick Pen: an open end on a selected segment continues its path A click on an open end of another path that lies on a segment of the selected path now goes on drawing from that end, and the pointer shows that it will. Before, the segment took the press and the click started a new path. An anchor of the selected path still comes first. --- crates/engine/src/tests/quickpen.rs | 17 +++++++++++++++++ crates/tools/src/quickpen.rs | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index e9181b03d7..aa0b7b088b 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -821,6 +821,23 @@ fn a_segment_drag_moves_only_its_ends() { assert_eq!(paths(&s).len(), 1); } +/// A click on an open end of another path, in front of the selected path, that lies on a segment +/// of the selected path goes on drawing from that end. +#[test] +fn an_open_end_on_a_selected_segment_continues_its_path() { + let mut s = session(); + let id = selected_quick_pen_path(&mut s, (100.0, 300.0), json!([{"x": 300, "y": 300}])); + let r = s.execute("shape.line", &json!({"x1": 200, "y1": 200, "x2": 200, "y2": 300})).unwrap(); + let other = NodeId(r["id"].as_u64().unwrap()); + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + click(&mut s, 200.0, 300.0); + click(&mut s, 250.0, 250.0); + let all = paths(&s); + assert_eq!(all.len(), 2, "no new path"); + let ends: Vec = all.iter().find(|(id, _)| *id == other).unwrap().1.subpaths[0].anchors.iter().map(|a| a.p).collect(); + assert_eq!(ends, [pt(200.0, 200.0), pt(200.0, 300.0), pt(250.0, 250.0)]); +} + /// Escape during a drag puts the anchor back, and the release then changes nothing. #[test] fn escape_takes_back_an_anchor_drag() { diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index 62819f793f..fa2c93709c 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -449,7 +449,10 @@ impl QuickPenTool { self.press = Some(Press { at: p, dragged: false, begun: true }); return vec![Action::Begin("Quick Pen".into()), Action::Preview(COMMAND.into(), self.params(false)), drawn()]; } - if let Some(grab) = edit::grab_at(cx, p, tol) { + // An anchor of a selected path comes first, then an open end, then a selected path's + // segment. + let grab = edit::grab_at(cx, p, tol); + if let Some(grab @ Grab::Anchor { .. }) = grab { self.edit = Some(Edit::new(cx, grab, p, shift)); return vec![]; } @@ -458,6 +461,10 @@ impl QuickPenTool { { return self.continue_path(cx, id, si, at_first); } + if let Some(grab) = grab { + self.edit = Some(Edit::new(cx, grab, p, shift)); + return vec![]; + } self.start_path(cx, p) } @@ -789,10 +796,14 @@ impl Tool for QuickPenTool { if let Some(e) = &self.edit { return if e.began { Cursor::Move } else { edit::cursor(cx, e.grab) }; } - if let Some(grab) = edit::grab_at(cx, p, tol) { + let grab = edit::grab_at(cx, p, tol); + if let Some(grab @ Grab::Anchor { .. }) = grab { return edit::cursor(cx, grab); } - if open_end_at(cx, p, tol, None).is_some() { Cursor::PenContinue } else { Cursor::Pen } + if open_end_at(cx, p, tol, None).is_some() { + return Cursor::PenContinue; + } + grab.map_or(Cursor::Pen, |grab| edit::cursor(cx, grab)) } fn options(&self) -> Value { From b88f48fd92c461fc517146dae5a8d041ebb0a0cc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 01:19:33 -0800 Subject: [PATCH 9/9] Quick Pen: a segment drag from its selected ends selects the segment A drag on a segment whose two ends were already selected as anchors kept that anchor selection, so Delete afterwards removed both anchors instead of cutting the connection. The drag now keeps the current selection only when that segment alone is selected; otherwise it selects the segment with select.segments, as it does from a path selected whole. --- crates/engine/src/tests/quickpen.rs | 22 ++++++++++++++++++++++ crates/tools/src/quickpen/edit.rs | 6 ++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index e9c8970e00..7d15e67609 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -1135,6 +1135,28 @@ fn a_segment_drag_moves_only_its_ends() { assert_eq!(paths(&s).len(), 1); } +/// A drag on a segment whose two ends are already selected as anchors selects the segment, so +/// Delete then cuts that connection and keeps both anchors. +#[test] +fn a_segment_drag_from_its_selected_ends_selects_the_segment() { + let mut s = session(); + let pieces = json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}, {"x": 400, "y": 100}]); + let id = selected_quick_pen_path(&mut s, (100.0, 100.0), pieces); + click(&mut s, 200.0, 100.0); + shift_click(&mut s, 300.0, 100.0); + let picked = s.doc().unwrap().selection.partial(id).cloned().unwrap_or_default().into_iter().collect::>(); + assert_eq!(picked, [(0, 1), (0, 2)]); + press(&mut s, &[(250.0, 100.0), (250.0, 120.0), (250.0, 150.0)]); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 150.0), pt(300.0, 150.0), pt(400.0, 100.0)]); + let segments = s.doc().unwrap().selection.segments.get(&id).cloned().unwrap_or_default().into_iter().collect::>(); + assert_eq!(segments, [(0, 1)], "the segment is selected"); + s.execute("edit.clear", &json!({})).unwrap(); + let left: Vec = paths(&s).iter().flat_map(|(_, pd)| pd.subpaths.iter().flat_map(|sp| sp.anchors.iter().map(|a| a.p))).collect(); + for p in [pt(100.0, 100.0), pt(200.0, 150.0), pt(300.0, 150.0), pt(400.0, 100.0)] { + assert!(left.contains(&p), "{p:?} stays: {left:?}"); + } +} + /// A click on an open end of another path, in front of the selected path, that lies on a segment /// of the selected path goes on drawing from that end. #[test] diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index 2620118b91..e06680d282 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -162,13 +162,15 @@ impl Edit { } let Some(picked) = self.grab.anchors(cx) else { return out }; // A drag on one of several selected anchors moves them all; a drag on a segment moves - // its two ends alone. + // its two ends alone and leaves that segment selected, not its ends as anchors. let already = match self.grab { Grab::Anchor { .. } => cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a))), - Grab::Segment { .. } => { + Grab::Segment { si, seg, .. } => { cx.selection.objects == [id] && cx.selection.anchors.len() == 1 && cx.selection.partial(id).is_some_and(|s| s.len() == picked.len() && picked.iter().all(|a| s.contains(a))) + && cx.selection.segments.len() == 1 + && cx.selection.segments.get(&id).is_some_and(|s| s.len() == 1 && s.contains(&(si, seg))) } }; let moving = if already {