From cb3946fe2f041f18e86de7e5be23d8be95f6345a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 22:23:15 -0800 Subject: [PATCH] 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 {