Merge pull request #19230

Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
davidmann4andautocraft-bot[bot] authored and autocraft-bot[bot] committed 2026-12-02 22:19:56 +00:00
commit 322277e907
4 files changed
+133 -16

No files matched your search

+18 -6
View File
@@ -233,7 +233,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 {
@@ -353,6 +354,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<'_, '_> {
@@ -436,7 +439,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 {
@@ -544,7 +553,8 @@ fn with_rig<R>(
(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);
@@ -618,7 +628,7 @@ fn with_rig<R>(
},
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))),
@@ -644,7 +654,7 @@ fn with_rig<R>(
&& !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
@@ -658,7 +668,9 @@ fn with_rig<R>(
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));
+26 -3
View File
@@ -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<Run>,
/// 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);
+8 -7
View File
@@ -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 {
@@ -845,3 +843,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;
@@ -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<PhotocraftApp>>) -> f64 {
testing::view(h.state()).unwrap().rotation
}
fn cursor(h: &Harness<'static, Box<PhotocraftApp>>) -> Option<Cursor> {
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");
}
}