From b88f48fd92c461fc517146dae5a8d041ebb0a0cc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 01:19:33 -0800 Subject: [PATCH] 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 {