From 3c15887fd99c86b6c957a930588aa89f6a575c16 Mon Sep 17 00:00:00 2001 From: jayzed80 Date: Sat, 14 Nov 2026 22:58:57 +0000 Subject: [PATCH] fix(tools): select the point Direct Selection presses on an unselected path Pressing an anchor of a path that wasn't selected selected only the path, so the point stayed hollow while it was dragged. It is now selected too and draws solid, as when the path was already selected. Fixes #2564 --- crates/engine/src/tests.rs | 33 +++++++++++++++++++++++++++++++++ crates/tools/src/select.rs | 4 +++- crates/tools/src/tests.rs | 5 ++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 08c30cdef..98b19fad5 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -2317,6 +2317,39 @@ fn direct_selection_pulls_one_corner_of_an_unselected_frame() { assert!(corners(&s).iter().zip(&before).all(|(p, q)| (p.y - q.y - 50.0).abs() < 1e-6), "{:?}", corners(&s)); } +/// Issue #2564: with Direct Selection, pressing a point of a path that isn't selected selects +/// that point (drawn solid), whether the press is a click or a drag. +#[test] +fn direct_selection_press_on_an_unselected_path_selects_the_point() { + use designcraft_tools::{PointerEvent, PointerKind, SnapView}; + let mut s = session(); + let id = s.execute("path.create", &json!({"anchors": [{"p": [100, 300]}, {"p": [300, 400]}]})).unwrap()["id"].as_u64().unwrap(); + s.set_tool("directSelection"); + let v = ViewInfo { snap: SnapView::OFF, ..ViewInfo::at_zoom(1.0) }; + let layout = s.layout(); + let at = |x: f64, y: f64| layout.to_canvas(designcraft_doc::SpreadRef::Doc(0), designcraft_geom::Point::new(x, y)); + let item = designcraft_doc::ItemId(id); + // A click on the end point. + s.execute("edit.deselectAll", &json!({})).unwrap(); + let p = at(300.0, 400.0); + s.pointer(&PointerEvent::new(PointerKind::Down, p.x, p.y), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, p.x, p.y), v).unwrap(); + let sel = s.doc().unwrap().selection.clone(); + assert_eq!(sel.items, [item]); + assert_eq!(sel.anchors, [(item, 0, 1)], "the clicked point is selected"); + // A drag from the start point: it moves and stays selected. + s.execute("edit.deselectAll", &json!({})).unwrap(); + let (a, b) = (at(100.0, 300.0), at(100.0, 250.0)); + s.pointer(&PointerEvent::new(PointerKind::Down, a.x, a.y), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, a.x, a.y - 20.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, b.x, b.y), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, b.x, b.y), v).unwrap(); + let st = s.doc().unwrap(); + let it = st.doc.item(item).unwrap(); + assert!((it.xf * it.path.subpaths[0].anchors[0].p - designcraft_geom::Point::new(100.0, 250.0)).hypot() < 1e-6); + assert_eq!(st.selection.anchors, [(item, 0, 0)], "the dragged point is selected"); +} + #[test] fn direct_selection_on_a_selected_frame_deletes_only_its_image() { use designcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey}; diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs index 1fb30e6f7..895c57224 100644 --- a/crates/tools/src/select.rs +++ b/crates/tools/src/select.rs @@ -848,7 +848,9 @@ impl SelectionTool { { let at = anchor_spread_point(cx, id, si, ai); self.drag = Drag::Anchor { id, si, ai, handle: None, start: p, at, others: vec![] }; - return vec![Action::Exec("selection.set".into(), json!({"ids": [id], "content": false})), Action::Begin("Move Anchor".into())]; + // The point pressed is selected too, so it draws solid like any selected point. + let points = json!({"ids": [id], "content": false, "anchors": [[id, si, ai]]}); + return vec![Action::Exec("selection.set".into(), points), Action::Begin("Move Anchor".into())]; } // A selected placed graphic's own handles resize it inside its frame (the // frame's anchors, under Direct Selection, come first). diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rs index acbef71fa..ec55a4d27 100644 --- a/crates/tools/src/tests.rs +++ b/crates/tools/src/tests.rs @@ -2306,7 +2306,10 @@ fn pulling_a_corner_of_an_unselected_frame_selects_the_frame_not_its_content() { let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y)); assert_eq!( acts, - vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [a.0], "content": false})), Action::Begin("Move Anchor".into())] + vec![ + Action::Exec("selection.set".into(), serde_json::json!({"ids": [a.0], "content": false, "anchors": [[a.0, 0, 1]]})), + Action::Begin("Move Anchor".into()) + ] ); }