Anchor tools: a selected saved path is the only target; the Pen draft is edited again (#12762, #12705)

hit_active now searches only the saved path selected in the Paths panel when there is one, instead of falling through to the active shape or work path. Without a selected saved path it puts the Pen draft first, as direct_select::candidates does. The draft's destination is private to vector_ui, so it is not filtered here.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
Trevor BrownandClaude Sonnet 5.5 committed 2026-11-10 08:44:01 -05:00
1 parent 3d56b2df67
commit bb35b99464
3 files changed
+39 -1

No files matched your search

@@ -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));
}
@@ -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);
}
+17 -1
View File
@@ -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)))