From 3dbb4c2137d3de944e424104a80b35c960afb06c Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 8 Nov 2026 15:13:47 -0800 Subject: [PATCH] Preserve the public layer picker lock default --- crates/engine/src/cmd/pick_cmds.rs | 18 +++++++++++++----- crates/ui-egui/src/tools/move_box.rs | 6 ++++-- crates/ui-egui/src/tools/move_distance.rs | 8 ++++++-- crates/ui-egui/src/tools/move_hover.rs | 13 +++++++++++-- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/cmd/pick_cmds.rs b/crates/engine/src/cmd/pick_cmds.rs index b774666c809..87f532b7bcc 100644 --- a/crates/engine/src/cmd/pick_cmds.rs +++ b/crates/engine/src/cmd/pick_cmds.rs @@ -84,12 +84,15 @@ fn top_group(doc: &Document, id: LayerId) -> LayerId { path.get(..depth).and_then(|p| doc.layer_at(p)).map_or(id, |l| l.id) } -/// The layer an Auto-Select click at (x, y) picks (with `group`, its outermost group): the topmost -/// movable hit, a type layer by its text bounds. It clicks through Position or All locks -/// (including locks inherited from a group) to the layer under it; the right-click list -/// still shows it. The Move tool's rollover highlight and `layer.pickAt` with `moveAutoSelect` -/// use the same eligibility, so the outline names the layer the click takes. +/// The topmost selectable layer at (x, y), or its outermost group if `group` is set. +/// Type layers hit across their text bounds. Effective Lock All is skipped. Position-locked layers remain selectable. pub fn auto_select_target(doc: &Document, x: i32, y: i32, group: bool) -> Option { + pick_target(doc, x, y, group, false) +} + +/// The Move tool's Auto-Select target, matching `layer.pickAt` with `moveAutoSelect` enabled. +/// Both effective Position and All locks are skipped before resolving the group. +pub fn move_auto_select_target(doc: &Document, x: i32, y: i32, group: bool) -> Option { pick_target(doc, x, y, group, true) } @@ -351,13 +354,16 @@ mod tests { let top = s.active().unwrap().active_layer.unwrap(); let lock = |s: &mut Session, id: u64, locks: Value| s.execute("layer.setProps", json!({"layer": id, "locks": locks})).unwrap(); let pick = |s: &mut Session| s.execute("layer.pickAt", json!({"x": 5, "y": 5, "moveAutoSelect": true})).unwrap()["layer"].clone(); + let direct = |s: &Session| auto_select_target(&s.active().unwrap().doc, 5, 5, false); assert_eq!(pick(&mut s), top.0); // Position and All locks are both skipped; Image Pixels still permits picking. lock(&mut s, top.0, json!({"position": true})); + assert_eq!(direct(&s), Some(top), "ordinary Rust callers can select a position-locked layer"); assert_eq!(pick(&mut s), a.0); lock(&mut s, top.0, json!({"position": false, "pixels": true})); assert_eq!(pick(&mut s), top.0); lock(&mut s, top.0, json!({"all": true})); + assert_eq!(direct(&s), Some(a)); assert_eq!(pick(&mut s), a.0); assert_eq!(s.active().unwrap().active_layer, Some(a)); // The right-click layer list still names it. @@ -369,8 +375,10 @@ mod tests { let g = s.execute("layer.new.groupFromLayers", json!({"name": "G"})).unwrap()["layer"].as_u64().unwrap(); assert_eq!(pick(&mut s), top.0); lock(&mut s, g, json!({"position": true})); + assert_eq!(direct(&s), Some(top), "inherited Position has the same ordinary default"); assert_eq!(pick(&mut s), a.0); lock(&mut s, g, json!({"all": true})); + assert_eq!(direct(&s), Some(a)); assert_eq!(pick(&mut s), a.0); // Nothing unlocked under the point: no pick. lock(&mut s, a.0, json!({"all": true})); diff --git a/crates/ui-egui/src/tools/move_box.rs b/crates/ui-egui/src/tools/move_box.rs index 4fb64971b6f..cea3e53b3f8 100644 --- a/crates/ui-egui/src/tools/move_box.rs +++ b/crates/ui-egui/src/tools/move_box.rs @@ -22,8 +22,10 @@ pub(crate) struct LayerBox { clear_on_empty: bool, } -/// A Move-tool press that Auto-Select found nothing under: start the marquee at `p`. The press -/// started a Move gesture's snapping and ⇧/⌥ handling, which a marquee has none of. +/// Start the marquee at `p` after an empty or locked-only hit. With `move_auto_select`, the +/// real Move tool skips effective Position as well as All locks. Set `clear_on_empty` for its +/// locked-only press so an empty replacement marquee clears the selection. +/// Temporary Move keeps ordinary lock filtering. Marquees clear the press's snapping and ⇧/⌥ state. pub(crate) fn begin(app: &mut PhotocraftApp, p: [f64; 2], add: bool, move_auto_select: bool, clear_on_empty: bool) { app.layer_box = Some(LayerBox { start: p, end: p, add, move_auto_select, clear_on_empty }); app.prefs_rt.snap = None; diff --git a/crates/ui-egui/src/tools/move_distance.rs b/crates/ui-egui/src/tools/move_distance.rs index a5603590c45..e57af527c9a 100644 --- a/crates/ui-egui/src/tools/move_distance.rs +++ b/crates/ui-egui/src/tools/move_distance.rs @@ -7,7 +7,7 @@ //! //! It's an overlay only: nothing changes in the document and there is no command or History //! state. The hovered layer is the one a click there would Auto-Select -//! (`pick_cmds::auto_select_target`), cached per document revision, selection and pointer pixel, +//! (`pick_cmds::move_auto_select_target`), cached per document revision, selection and pointer pixel, //! so a pointer resting on the canvas costs nothing per frame. use egui::{Color32, Pos2, Stroke, pos2, vec2}; @@ -117,7 +117,7 @@ fn boxes(app: &mut PhotocraftApp, at: [f64; 2]) -> Option<([f64; 4], [f64; 4])> let d = &st.doc; let a = union(selected.iter().filter(|id| !d.is_background(**id)).filter_map(|id| tree_rect(d, *id))); let canvas = [0.0, 0.0, d.size.width as f64, d.size.height as f64]; - let hovered = photocraft_engine::pick_cmds::auto_select_target(d, at[0], at[1], group).filter(|id| { + let hovered = photocraft_engine::pick_cmds::move_auto_select_target(d, at[0], at[1], group).filter(|id| { // The selection itself (or a layer in a selected group) isn't another layer. !d.is_background(*id) && !selected.iter().any(|s| *s == *id || d.path_of(*id).zip(d.path_of(*s)).is_some_and(|(p, q)| p.starts_with(&q))) }); @@ -279,6 +279,10 @@ mod tests { assert_eq!(current(&mut app, Some([60.0, 60.0]), true, false).unwrap().measures.len(), 4); // Only an overlay: the document didn't change. assert_eq!(app.session.active().unwrap().revision, revision); + let target = app.session.active().unwrap().doc.layers.iter().find(|l| l.name == "target").unwrap().id; + app.run("layer.setProps", json!({"layer": target.0, "locks": {"position": true}})).unwrap(); + let locked = current(&mut app, Some([320.5, 230.0]), true, false).unwrap(); + assert_eq!(locked.measures, o.measures, "a position-locked target measures to the canvas"); } #[test] diff --git a/crates/ui-egui/src/tools/move_hover.rs b/crates/ui-egui/src/tools/move_hover.rs index f60bc71c6a7..4594678fa10 100644 --- a/crates/ui-egui/src/tools/move_hover.rs +++ b/crates/ui-egui/src/tools/move_hover.rs @@ -1,7 +1,7 @@ //! Move tool › Show Highlight on Rollover (Preferences › Tools, on by default): with Auto-Select //! on, or ⌘ held while it is off, hovering the canvas outlines the layer (or group, per the //! Auto-Select target) that a click there would pick. The hit test is the click's own -//! (`pick_cmds::auto_select_target`), so a type layer is outlined anywhere inside its text, as it +//! (`pick_cmds::move_auto_select_target`), so a type layer is outlined anywhere inside its text, as it //! is picked there (#2591). The answer is cached per document revision and pointer pixel: a //! pointer resting on the canvas costs nothing per frame. @@ -53,7 +53,7 @@ pub(crate) fn target(app: &mut PhotocraftApp, at: Option<[f64; 2]>, command: boo app.canvas_hover_layer = h.target_layer; return h.bounds; } - let target_layer = photocraft_engine::pick_cmds::auto_select_target(&st.doc, at[0], at[1], group); + let target_layer = photocraft_engine::pick_cmds::move_auto_select_target(&st.doc, at[0], at[1], group); let bounds = target_layer.and_then(|id| outline(&st.doc, id)); let target_layer = if bounds.is_some() { target_layer } else { None }; app.move_hover = Some(Hover { doc, revision, at, group, target_layer, bounds }); @@ -155,6 +155,15 @@ mod tests { // The empty top layer is clicked through to the painted one; the Background isn't outlined. assert_eq!(target(&mut app, Some([10.5, 12.0]), false, false), Some(a)); assert_eq!(target(&mut app, Some([40.0, 40.0]), false, false), None); + app.session + .edit("paint top", |doc, active| { + let top = doc.layer_mut(active.unwrap()).unwrap(); + top.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 32, 32), &[0.0, 0.0, 1.0, 1.0]); + top.locks.position = true; + Ok(()) + }) + .unwrap(); + assert_eq!(target(&mut app, Some([10.5, 12.0]), false, false), Some(a), "the rollover skips the position-locked top layer"); // Nothing while a button is down or a drag runs. assert_eq!(target(&mut app, Some([10.5, 12.0]), false, true), None); // Auto-Select off: only with ⌘ held.