From 131a546f0ad175d24895b3b26262d8708d95201c Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 2 Dec 2026 15:52:05 +0000 Subject: [PATCH 1/2] test(ui): cover temporary Move from Rotate View --- crates/ui-egui/src/input/hold_keys/tests.rs | 3 + .../src/rotate_view_ctrl_move_tests.rs | 81 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 crates/ui-egui/src/rotate_view_ctrl_move_tests.rs diff --git a/crates/ui-egui/src/input/hold_keys/tests.rs b/crates/ui-egui/src/input/hold_keys/tests.rs index 2dae9cad764..4ed902133e3 100644 --- a/crates/ui-egui/src/input/hold_keys/tests.rs +++ b/crates/ui-egui/src/input/hold_keys/tests.rs @@ -845,3 +845,6 @@ fn space_after_an_alt_tap_or_f10_pans_and_opens_no_menu() { assert_eq!(h.state().ui.tool, Tool::Brush, "f10 {f10}, clicked {clicked}: the tool comes back"); } } + +#[path = "../../rotate_view_ctrl_move_tests.rs"] +mod rotate_view_ctrl_move_tests; diff --git a/crates/ui-egui/src/rotate_view_ctrl_move_tests.rs b/crates/ui-egui/src/rotate_view_ctrl_move_tests.rs new file mode 100644 index 00000000000..0d02c9f90bb --- /dev/null +++ b/crates/ui-egui/src/rotate_view_ctrl_move_tests.rs @@ -0,0 +1,81 @@ +//! #19014 through native pointer events in the canvas harness. + +use craft::behavior::PointerGlyph; + +use super::*; + +fn rotation(h: &Harness<'static, Box>) -> f64 { + testing::view(h.state()).unwrap().rotation +} + +fn cursor(h: &Harness<'static, Box>) -> Option { + h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone()) +} + +#[test] +fn command_drag_uses_move_marquee_and_returns_to_rotate_view() { + let mut h = harness(Tool::RotateView); + let first = with_layer(&mut h); + let second = with_layer(&mut h); + h.state_mut().run("layer.translate", json!({"dx": 80, "dy": 0})).unwrap(); + let bounds_before = [bounds(&h, first), bounds(&h, second)]; + let history_before = h.state().session.active().unwrap().history.past_len(); + let angle_before = rotation(&h); + let start = screen(&h, -15.0, 80.0); + let end = screen(&h, 240.0, 170.0); + h.event(Event::PointerMoved(start)); + h.run_steps(2); + let rotate_cursor = cursor(&h); + assert_eq!(rotate_cursor, Some(Cursor::Painted(PaintedCursor::Hand))); + + hold_mods(&mut h, Modifiers::COMMAND); + let move_cursor = PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(Tool::Move)); + assert_eq!(cursor(&h), Some(Cursor::Painted(move_cursor))); + button(&mut h, start, true, Modifiers::COMMAND); + // Releasing Command before the pointer must leave the drag with the Move tool until release. + hold_mods(&mut h, Modifiers::NONE); + h.event(Event::PointerMoved(end)); + h.run_steps(2); + button(&mut h, end, false, Modifiers::NONE); + h.run_steps(2); + + let st = h.state().session.active().unwrap(); + assert_eq!(st.selected_layers().len(), 2); + assert!(st.selected_layers().contains(&first) && st.selected_layers().contains(&second)); + assert_eq!(st.history.past_len(), history_before); + assert_eq!([bounds(&h, first), bounds(&h, second)], bounds_before); + assert_eq!(rotation(&h), angle_before); + assert_eq!(h.state().ui.tool, Tool::RotateView); + assert_eq!(cursor(&h), rotate_cursor); +} + +#[test] +fn command_click_keeps_the_selected_layer() { + let mut h = harness(Tool::RotateView); + let first = with_layer(&mut h); + let second = with_layer(&mut h); + h.state_mut().run("layer.translate", json!({"dx": 80, "dy": 0})).unwrap(); + assert_ne!(first, second); + + hold_mods(&mut h, Modifiers::COMMAND); + click(&mut h, 130.0, 130.0, Modifiers::COMMAND); + assert_eq!(h.state().session.active().unwrap().selected_layers(), [second]); +} + +#[test] +fn plain_shift_alt_and_command_alt_drags_keep_rotating() { + for mods in [Modifiers::NONE, Modifiers::SHIFT, Modifiers::ALT, Modifiers::COMMAND | Modifiers::ALT] { + let mut h = harness(Tool::RotateView); + let angle_before = rotation(&h); + let start = screen(&h, 130.0, 120.0); + let end = screen(&h, 250.0, 90.0); + hold_mods(&mut h, mods); + h.event(Event::PointerMoved(start)); + h.run_steps(1); + button(&mut h, start, true, mods); + h.event(Event::PointerMoved(end)); + h.run_steps(2); + button(&mut h, end, false, mods); + assert_ne!(rotation(&h), angle_before, "{mods:?} drag should rotate"); + } +} From be52fb47c3ccf0c300c2e1924d97a8f9050d6355 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 2 Dec 2026 15:54:17 +0000 Subject: [PATCH 2/2] fix(ui): lend Rotate View command drags to Move --- crates/ui-egui/src/canvas/tools/mod.rs | 24 ++++++++++++---- crates/ui-egui/src/canvas/tools/move_tool.rs | 29 ++++++++++++++++++-- crates/ui-egui/src/input/hold_keys/tests.rs | 12 ++++---- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/canvas/tools/mod.rs b/crates/ui-egui/src/canvas/tools/mod.rs index 0f9031be618..ddcb7373c3a 100644 --- a/crates/ui-egui/src/canvas/tools/mod.rs +++ b/crates/ui-egui/src/canvas/tools/mod.rs @@ -229,7 +229,8 @@ pub(crate) fn family(tool: Tool) -> Family { } /// Whether holding ⌘ (Ctrl off the Mac) over `tool` makes the Move tool take the press: every tool but the ones ⌘ means -/// something else to (Hand, Rotate View, Zoom, the crops, Slice, the path and shape tools, the Type tools). The +/// something else to (Hand, Zoom, the crops, Slice, the path and shape tools, the Type tools). Rotate View hands off +/// only drags, so it keeps the ordinary press behavior around guides and other controls. The /// selection tools read ⌘ per press themselves and hand the press to the stand-in (`Ignored`) where ⌘ moves the layer. /// `run` installs the Command stand-in by it and the snap targets of the moving set follow it. pub(crate) fn takes_command_stand_in(tool: Tool) -> bool { @@ -349,6 +350,8 @@ struct Preflight<'a, 'x> { outline_open: bool, /// The pass has an Alt stand-in, so a press the preflight hands on (`Ignored`) reaches it. alt_stand_in: bool, + /// Rotate View's primary drag can go to Move when the unmodified Command chord is held. + rotate_view_stand_in: bool, } impl CanvasTool for Preflight<'_, '_> { @@ -432,7 +435,13 @@ impl CanvasTool for Preflight<'_, '_> { } fn takes(&self, button: PointerButton, mods: Mods) -> bool { - (!self.dialog && self.scope.with_app(|app| super::quick_pick::takes(app, mods))) || self.inner.takes(button, mods) + if !self.dialog && self.scope.with_app(|app| super::quick_pick::takes(app, mods)) { + return true; + } + if self.rotate_view_stand_in && button == PointerButton::Primary && mods == Mods::CMD { + return false; + } + self.inner.takes(button, mods) } fn autoscrolls(&self) -> bool { @@ -540,7 +549,8 @@ fn with_rig( (Some(tool), Some(run)) => Some(crop::pass(tool, run, ctx, crop_shown)), _ => None, }; - let command_wanted = stand_ins && !scale_ruler && !transform_open && takes_command_stand_in(tool); + let rotate_view = fam == Family::RotateView; + let command_wanted = stand_ins && !scale_ruler && !transform_open && (rotate_view || takes_command_stand_in(tool)); let alt_wanted = stand_ins && !transform_open && super::cursor_policy::alt_eyedropper(tool); let source_wanted = stand_ins && matches!(tool, Tool::CloneStamp | Tool::Healing); @@ -614,7 +624,7 @@ fn with_rig( }, Family::Selection => dynamic(boxed.insert(selection::tool(&scope, selection, host))), Family::Move => match mover.take() { - Some(state) => dynamic(boxed.insert(move_tool::tool(&scope, state, host))), + Some(state) => dynamic(boxed.insert(move_tool::tool(&scope, state, false))), None => dynamic(boxed.insert(Box::new(NoTool))), }, Family::Paint => dynamic(boxed.insert(super::paint_tool::tool(&scope, paint, host))), @@ -640,7 +650,7 @@ fn with_rig( && !dialog_picked && let Some(state) = mover.take() { - command_t = Some(move_tool::tool(&scope, state, host)); + command_t = Some(move_tool::tool(&scope, state, rotate_view)); } if alt_wanted && !dialog_picked @@ -654,7 +664,9 @@ fn with_rig( alt_t = Some(retouch::source_tool(&scope, state, host)); } let alt_stand_in = alt_t.is_some(); - let mut pre = Preflight { scope: &scope, inner: selected, tool, dialog: dialog_picked || scale_ruler, outline_open, alt_stand_in }; + let rotate_view_stand_in = rotate_view && command_t.is_some(); + let mut pre = + Preflight { scope: &scope, inner: selected, tool, dialog: dialog_picked || scale_ruler, outline_open, alt_stand_in, rotate_view_stand_in }; let mut tool_host = ToolHost::new().momentary(momentary); if let Some(mover) = command_t.as_mut() { tool_host = tool_host.stand_in(StandInKey::Command, dynamic(mover)); diff --git a/crates/ui-egui/src/canvas/tools/move_tool.rs b/crates/ui-egui/src/canvas/tools/move_tool.rs index 4c53eba55d3..ff74a7e4484 100644 --- a/crates/ui-egui/src/canvas/tools/move_tool.rs +++ b/crates/ui-egui/src/canvas/tools/move_tool.rs @@ -9,7 +9,6 @@ use super::{FamilyTool, ToolScope}; use crate::PhotocraftApp; -use crate::canvas::document_display::CanvasHost; use crate::state::Tool; use craft::behavior::geometry::{ConstrainStyle, Directions, MoveGesture, SnapKinds}; use craft::behavior::kurbo::{self, Point}; @@ -75,6 +74,8 @@ pub(crate) struct MoveLayerDrag { #[derive(Default)] pub(crate) struct MoveTool { run: Option, + /// Rotate View hands over drags while retaining its own click behavior. + pending_drag: Option<([f64; 2], Mods)>, } impl MoveTool { @@ -102,8 +103,8 @@ impl MoveTool { } /// The Move family's tool for a pass (`tools::run`), and the ⌘ stand-in of the families that refuse ⌘. -pub(crate) fn tool<'a>(scope: &'a ToolScope<'a>, state: &'a mut MoveTool, _host: CanvasHost) -> FamilyTool<'a> { - Box::new(MoveRun { scope, state }) +pub(crate) fn tool<'a>(scope: &'a ToolScope<'a>, state: &'a mut MoveTool, drag_only: bool) -> FamilyTool<'a> { + Box::new(MoveRun { scope, state, drag_only }) } /// The Move tool as the host runs it: the pass's scope over the app, and the tool's own state. @@ -117,6 +118,7 @@ fn floating(app: &PhotocraftApp) -> bool { pub(crate) struct MoveRun<'a> { scope: &'a ToolScope<'a>, state: &'a mut MoveTool, + drag_only: bool, } /// Auto-Select's pick moved the active layer: the Layers panel's reveal honours it (`layer_reveal`). @@ -326,6 +328,10 @@ impl CanvasTool for MoveRun<'_> { fn press(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) -> ToolAction { let Some(space) = cx.space() else { return ToolAction::Ignored }; let at = space.view.to_doc(pointer.pos); + if self.drag_only { + self.state.pending_drag = Some(([at.x, at.y], pointer.mods)); + return ToolAction::Claimed; + } let style = ConstrainStyle::new(f64::from(cx.slop), f64::from(cx.slop)); // A double-click on type edits it, as in Photoshop (#1132): only the selected Move tool, not a ⌘ stand-in for // another tool, and not while a transform box is open (its double-click commits). @@ -348,6 +354,11 @@ impl CanvasTool for MoveRun<'_> { } fn drag(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) { + if let Some((at, mods)) = self.state.pending_drag.take() { + let style = ConstrainStyle::new(f64::from(cx.slop), f64::from(cx.slop)); + let (_, run) = self.scope.with_app(|app| press_at(app, at, mods, style)); + self.state.run = run; + } let Some(run) = self.state.run.as_mut() else { return }; let Some(space) = cx.space() else { return }; let at = space.view.to_doc(pointer.pos); @@ -368,6 +379,17 @@ impl CanvasTool for MoveRun<'_> { } fn release(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) { + if self.state.pending_drag.take().is_some() { + // Rotate View's double-click still resets the view. + if pointer.clicks >= 2 + && let Some(space) = cx.space() + { + let mut view = space.view; + view.rotation = 0.0; + cx.set_view(view); + } + return; + } let Some(mut run) = self.state.run.take() else { return }; let Some(space) = cx.space() else { return }; let at = space.view.to_doc(pointer.pos); @@ -407,6 +429,7 @@ impl CanvasTool for MoveRun<'_> { fn cancel(&mut self, _reason: CancelReason, _cx: &mut ToolContext<'_>) { self.state.run = None; + self.state.pending_drag = None; self.scope.with_app(|app| { crate::move_box::cancel(app); crate::move_mods::abandon(app); diff --git a/crates/ui-egui/src/input/hold_keys/tests.rs b/crates/ui-egui/src/input/hold_keys/tests.rs index 4ed902133e3..979d6b9aeb2 100644 --- a/crates/ui-egui/src/input/hold_keys/tests.rs +++ b/crates/ui-egui/src/input/hold_keys/tests.rs @@ -372,13 +372,11 @@ fn cmd_gives_the_move_tool_only_where_the_tool_does_not_take_cmd() { assert_eq!(st.history.past_len(), steps + 1, "{tool:?}: one step, nothing painted"); assert_eq!(h.state().ui.tool, tool, "{tool:?}: the tool is back"); } - // The Crop and Rotate View tools go last, in an app of their own: they leave a pending crop and - // a turned view behind. - // One tool per decision the refusal comes from: the Hand, Zoom and Rotate-View families, the vector family's - // shared line (the Pen stands for the shapes and both path tools), and the Type tools' `is_type` line (the - // vertical type tool takes the same branch). Every tool's own decision is asserted in - // `the_command_stand_in_rule_is_the_table`, without a drag. - let keeps = [vec![Tool::Hand, Tool::Zoom, Tool::Pen, Tool::Type], vec![Tool::Crop, Tool::RotateView]]; + // The Crop tool goes last in an app of its own because it leaves a pending crop behind. + // Test the Hand and Zoom families, the vector family's shared line (the Pen stands for the shapes and path + // tools), and the Type tools' `is_type` line (the vertical Type tool takes the same branch). The held Rotate + // View drag has its own test because its click behavior differs from the other Move stand-ins. + let keeps = [vec![Tool::Hand, Tool::Zoom, Tool::Pen, Tool::Type], vec![Tool::Crop]]; for group in keeps { let mut h = harness(group[0]); for tool in group {