From 0df9babc47a145c8fbc4d88253a9a94d3ba64d75 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 6 Nov 2026 22:11:06 -0800 Subject: [PATCH] Document Move selection and gesture behavior --- crates/engine/src/cmd/pick_cmds.rs | 6 ++++++ crates/ui-egui/src/canvas/tool_input.rs | 3 +++ crates/ui-egui/src/move_shift_click_tests.rs | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/crates/engine/src/cmd/pick_cmds.rs b/crates/engine/src/cmd/pick_cmds.rs index 7ef0775a10..5a68237712 100644 --- a/crates/engine/src/cmd/pick_cmds.rs +++ b/crates/engine/src/cmd/pick_cmds.rs @@ -93,6 +93,8 @@ pub fn auto_select_target(doc: &Document, x: i32, y: i32, group: bool) -> Option pick_target(doc, x, y, group, true) } +/// Choose the topmost hit eligible for selection before resolving its group. An effective Lock +/// All excludes a layer from selection here. Move Auto-Select also skips effective Position locks. fn pick_target(doc: &Document, x: i32, y: i32, group: bool, move_auto_select: bool) -> Option { let hit = layers_hit(doc, x, y, true).into_iter().find(|id| { let locks = doc.effective_locks(*id); @@ -101,6 +103,8 @@ fn pick_target(doc: &Document, x: i32, y: i32, group: bool, move_auto_select: bo Some(if group { top_group(doc, hit) } else { hit }) } +/// List the hits for a context menu or pick one layer or group. A probe leaves the selection +/// alone. A replace click on a selected member keeps the full multi-selection for dragging. fn pick(s: &mut Session, p: &Value) -> Result { let x = p.get("x").and_then(Value::as_f64).ok_or_else(|| EngineError::BadParams { cmd: "layer.pickAt".into(), msg: "missing `x`".into() })?.floor() as i32; let y = p.get("y").and_then(Value::as_f64).ok_or_else(|| EngineError::BadParams { cmd: "layer.pickAt".into(), msg: "missing `y`".into() })?.floor() as i32; @@ -427,6 +431,8 @@ mod tests { assert_eq!(menu["layers"][1]["layer"], bg.0); } + /// A marquee normalizes reversed bounds and extends the existing selection in add mode. + /// An empty marquee preserves the selection in add mode and clears it in replace mode. #[test] fn a_marquee_selects_the_layers_it_touches() { let (mut s, a, b) = two_squares(); diff --git a/crates/ui-egui/src/canvas/tool_input.rs b/crates/ui-egui/src/canvas/tool_input.rs index cef4b055fc..16eb4d82b2 100644 --- a/crates/ui-egui/src/canvas/tool_input.rs +++ b/crates/ui-egui/src/canvas/tool_input.rs @@ -229,6 +229,9 @@ fn filter_event_before_tool(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui:: Some((raw, ev, mods)) } +/// Handle Move-specific pointer events and report whether the event was consumed. Auto-Select +/// picks on press so snapping and dragging use the resulting layer selection. When a locked-only +/// hit starts a marquee, Shift preserves the selection that the marquee adds to. fn handle_move_pointer(app: &mut PhotocraftApp, ev: ToolEvent, tool: Tool, mods: egui::Modifiers) -> bool { match ev { ToolEvent::Down { x, y, pressure } if tool == Tool::Move => { diff --git a/crates/ui-egui/src/move_shift_click_tests.rs b/crates/ui-egui/src/move_shift_click_tests.rs index ac191b3deb..c3019e3fa1 100644 --- a/crates/ui-egui/src/move_shift_click_tests.rs +++ b/crates/ui-egui/src/move_shift_click_tests.rs @@ -57,6 +57,8 @@ impl Fixture { std::iter::once(self.background).chain(self.layers).map(|id| doc.layer(id).unwrap().surface().unwrap().content_bounds()).collect() } + /// Send a click or drag through the tool event path. Equal endpoints send no move event. + /// The release must end any marquee without raising a move-lock error. fn gesture(&mut self, from: [f64; 2], to: [f64; 2], mods: Modifiers) { tool_event(&mut self.app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, mods); if from != to { @@ -130,6 +132,8 @@ fn shift_drag_moves_the_layers_selected_after_the_press() { } } +/// A plain click on locked-only pixels clears the selection. Shift keeps the base for an +/// additive marquee, and neither gesture moves the locked content. #[test] fn locked_only_click_clears_each_measured_selection_and_shift_keeps_its_base() { let mut f = Fixture::new(); @@ -155,6 +159,8 @@ fn locked_only_click_clears_each_measured_selection_and_shift_keeps_its_base() { assert_eq!(f.bounds(), before, "the all-locked layer and Background stay put"); } +/// Once Background becomes a normal layer, Position and All locks prevent Auto-Select. +/// An Image Pixels lock still permits selection, and the unlocked layer can be dragged. #[test] fn converted_background_point_pick_obeys_position_and_all_but_not_image_pixels_lock() { for (locks, selectable) in [(json!({}), true), (json!({"all": true}), false), (json!({"position": true}), false), (json!({"pixels": true}), true)] { @@ -176,6 +182,8 @@ fn converted_background_point_pick_obeys_position_and_all_but_not_image_pixels_l assert_eq!(f.bounds()[0], Rect::new(3, 2, 83, 62), "an unlocked converted Background can move"); } +/// Move Auto-Select picks the movable layer under a Position- or All-locked hit. The context +/// menu still lists the locked hit first so the user can choose it explicitly. #[test] fn locked_top_layer_is_clicked_through_while_the_context_menu_still_lists_it() { for locks in [json!({"position": true}), json!({"all": true})] { @@ -193,6 +201,8 @@ fn locked_top_layer_is_clicked_through_while_the_context_menu_still_lists_it() { } } +/// A marquee starting on Background adds hits with Shift and replaces the set without it. +/// Empty boxes preserve the additive base and clear a replacement, with no pixel movement. #[test] fn background_marquee_adds_with_shift_and_replaces_without_it_including_empty_hits() { let mut f = Fixture::new();