From f43da2ad9f57a8f4febfeefa304ab0c2905ff845 Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:37:15 +0900 Subject: [PATCH] Require the Freeform continuation endpoint to be selected --- .../ui-egui/src/tools/vector_ui/freeform.rs | 4 ++-- .../freeform_continue_endpoint_tests.rs | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tools/vector_ui/freeform.rs b/crates/ui-egui/src/tools/vector_ui/freeform.rs index 4999d640587..26ad0bbde37 100644 --- a/crates/ui-egui/src/tools/vector_ui/freeform.rs +++ b/crates/ui-egui/src/tools/vector_ui/freeform.rs @@ -116,8 +116,8 @@ impl FreeformPenTool { return None; } let anchor = sub.knots.last()?.anchor; - let selected = - work_selected && (selection.segment.is_some_and(|[index, _]| index == subpath) || selection.anchors.iter().any(|[index, _]| *index == subpath)); + let last = sub.knots.len() - 1; + let selected = work_selected && (selection.anchors.contains(&[subpath, last]) || selection.segment == Some([subpath, last - 1])); Some(WorkPathEnd { subpath, point: Point::new(anchor.x, anchor.y), selected }) })); } diff --git a/crates/ui-egui/src/tools/vector_ui/freeform_continue_endpoint_tests.rs b/crates/ui-egui/src/tools/vector_ui/freeform_continue_endpoint_tests.rs index 99196a814a6..991b8ee454b 100644 --- a/crates/ui-egui/src/tools/vector_ui/freeform_continue_endpoint_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/freeform_continue_endpoint_tests.rs @@ -100,3 +100,27 @@ fn a_single_anchor_is_not_a_measured_continuation_endpoint() { assert_eq!(work_path(&app).subpaths.len(), 2); assert_eq!(work_path(&app).subpaths[0], before.subpaths[0]); } + +#[test] +fn selecting_an_earlier_anchor_or_segment_leaves_the_end_unselected() { + let mut app = with_open_work_path(); + app.run("path.set", json!({"name":"work","path":{"subpaths":[{"closed":false,"knots":[[100,400],[300,400],[500,400]]}]}})).unwrap(); + assert!(!work_path(&app).subpaths[0].closed); + let before = work_path(&app).clone(); + let history = app.session.active().unwrap().history.past_len(); + for point in [[100.0, 400.0], [200.0, 400.0]] { + testing::click(&mut app, point, Modifiers::COMMAND); + assert_eq!(app.ui.direct_selection.target, Some(PathRef::Work)); + assert!(!shows_continue(&mut app, [500.0, 400.0])); + drag(&mut app, [500.0, 400.0], [700.0, 300.0]); + assert_eq!(work_path(&app), &before); + assert_eq!(app.session.active().unwrap().history.past_len(), history); + } + testing::click(&mut app, [400.0, 400.0], Modifiers::COMMAND); + assert_eq!(app.ui.direct_selection.segment, Some([0, 1])); + assert!(shows_continue(&mut app, [500.0, 400.0])); + drag(&mut app, [500.0, 400.0], [700.0, 300.0]); + assert_eq!(work_path(&app).subpaths.len(), 1); + assert_eq!(work_path(&app).subpaths[0].knots.len(), 4); + assert_eq!(app.session.active().unwrap().history.past_len(), history + 1); +}