diff --git a/crates/ui-egui/src/tools/anchor_tools/add_anchor_targeted_path_tests.rs b/crates/ui-egui/src/tools/anchor_tools/add_anchor_targeted_path_tests.rs index f2a7f4f5b7..9024408757 100644 --- a/crates/ui-egui/src/tools/anchor_tools/add_anchor_targeted_path_tests.rs +++ b/crates/ui-egui/src/tools/anchor_tools/add_anchor_targeted_path_tests.rs @@ -85,3 +85,14 @@ fn a_hidden_active_shape_is_not_edited() { assert_eq!(shape_path(&mut app, shape), before); assert_eq!(steps(&app), n); } + +#[test] +fn the_pen_draft_is_still_edited_by_the_anchor_tools() { + let (mut app, _shape) = setup(Tool::Pen); + click(&mut app, [100.0, 500.0]); + click(&mut app, [300.0, 500.0]); + assert_eq!(app.ui.pen.as_ref().map(|p| p.knots.len()), Some(2)); + app.ui.tool = Tool::AddAnchorPoint; + click(&mut app, [200.0, 500.0]); + assert_eq!(app.ui.pen.as_ref().map(|p| p.knots.len()), Some(3)); +} diff --git a/crates/ui-egui/src/tools/anchor_tools/delete_anchor_targeted_path_tests.rs b/crates/ui-egui/src/tools/anchor_tools/delete_anchor_targeted_path_tests.rs index 2fcd9852d8..2765b09c7a 100644 --- a/crates/ui-egui/src/tools/anchor_tools/delete_anchor_targeted_path_tests.rs +++ b/crates/ui-egui/src/tools/anchor_tools/delete_anchor_targeted_path_tests.rs @@ -82,3 +82,14 @@ fn direct_selection_still_edits_a_shape_layer_that_is_not_active() { click(&mut app, [650.0, 250.0]); assert_eq!(app.ui.direct_selection.target, Some(PathRef::Layer(shape))); } + +#[test] +fn with_a_saved_path_selected_a_click_on_the_active_shape_does_nothing() { + let (mut app, shape) = setup(Tool::DeleteAnchorPoint); + select_layer(&mut app, shape); + select_saved_path(&mut app); + let (before, n) = (shape_path(&mut app, shape), steps(&app)); + click(&mut app, [650.0, 250.0]); + assert_eq!(shape_path(&mut app, shape), before); + assert_eq!(steps(&app), n); +} diff --git a/crates/ui-egui/src/tools/direct_select.rs b/crates/ui-egui/src/tools/direct_select.rs index 50617c0832..1e834c51cd 100644 --- a/crates/ui-egui/src/tools/direct_select.rs +++ b/crates/ui-egui/src/tools/direct_select.rs @@ -353,7 +353,23 @@ pub(crate) fn hit_target(app: &PhotocraftApp, p: [f64; 2], handles: bool) -> Opt pub(crate) fn hit_active(app: &PhotocraftApp, p: [f64; 2]) -> Option<(PathRef, Path, Hit)> { let tol = 6.0 / f64::from(app.point_zoom().max(0.01)); let st = app.session.active()?; - active_paths(app) + // A path selected in the Paths panel is the only target; otherwise the Pen draft first (as + // `candidates` builds it), then the active paths. The draft's destination is private to + // `vector_ui`, so it is not filtered here. + let targets: Vec<(PathRef, Path)> = match crate::vector_ui::selected_saved_path_index(app) { + Some((i, path)) => Some((PathRef::Saved(i), path)).filter(|(r, _)| writable(app, r)).into_iter().collect(), + None => { + let pen = app + .ui + .pen + .as_ref() + .filter(|_| app.ui.pen_doc.is_none_or(|owner| Some(owner) == Some(st.doc.id))) + .filter(|p| !p.dragging && !p.knots.is_empty()) + .map(|p| (PathRef::Pen, crate::vector_ui::pen_path(p))); + pen.into_iter().chain(active_paths(app)).collect() + } + }; + targets .into_iter() .filter(|(r, _)| !matches!(r, PathRef::Layer(id) if !st.doc.layer(photocraft_doc::LayerId(*id)).is_some_and(|l| l.visible))) .find_map(|(r, path)| edit::hit(&path, Point::new(p[0], p[1]), tol, &[]).map(|h| (r, path, h)))