diff --git a/crates/ui-egui/src/hold_keys.rs b/crates/ui-egui/src/hold_keys.rs index 3f2845cae8..8b8bef092c 100644 --- a/crates/ui-egui/src/hold_keys.rs +++ b/crates/ui-egui/src/hold_keys.rs @@ -16,6 +16,8 @@ //! selection tools do their own ⌘ handling in `canvas` (⌘ inside the selection cuts the //! selected pixels, outside it moves the layer, #896), and the Hand, Zoom, Crop, Slice, Path //! Selection, shape, Pen and Type tools keep ⌘ for themselves. +//! - With the Hand tool selected, ⌘ (Ctrl off the Mac) is Zoom In while held and ⌥ (with or +//! without ⌘) Zoom Out ([`hand_zoom`], #6434). //! - `~` (the backtick key) with the Brush or Pencil: a stroke started while it is held erases, //! with that tool's own brush ([`erase_held`], #3439). //! @@ -118,6 +120,28 @@ fn cmd_move_held(app: &PhotocraftApp, i: &InputState) -> bool { i.modifiers.command && cmd_moves(app.ui.tool) && app.ui.transform.is_none() && app.ui.text_edit.is_none() } +/// The Hand tool's own modifiers (#6434): ⌘ (Ctrl off the Mac) held is Zoom In, ⌥ (with or +/// without ⌘) Zoom Out, as in Photoshop; the Modifier Keys panel's latched keys count. Not while +/// Free Transform is open (its box keeps ⌘ for the distort handles), and a modifier pressed during +/// a Hand press doesn't turn it into a zoom, release included: only a press made with it held +/// zooms (that one is latched by [`for_frame`] until the button comes up). A middle-button pan +/// stays a pan whatever is held. +fn hand_zoom(app: &PhotocraftApp, i: &InputState) -> Option { + let p = &i.pointer; + let hand_press = ((p.primary_down() || p.primary_released()) && !p.primary_pressed()) || p.middle_down(); + if app.ui.tool != Tool::Hand || app.ui.transform.is_some() || hand_press { + return None; + } + let m = crate::workspace_ui::sticky_mods(app, i.modifiers); + if m.alt { + Some(Temporary::ZoomOut) + } else if m.command { + Some(Temporary::ZoomIn) + } else { + None + } +} + /// Is `id` a held temporary tool rather than a command? pub fn is_temporary(id: &str) -> bool { photocraft_engine::prefs::TEMPORARY_TOOLS.iter().any(|t| t.0 == id) @@ -160,6 +184,7 @@ pub fn held_tool(app: &PhotocraftApp, ctx: &egui::Context) -> Option let mut best: Option<(u8, Temporary, KeyboardShortcut)> = None; let mut cmd_move = false; let mut alt = false; + let mut hand = None; ctx.input(|i| { for t in Temporary::BOUND { if let Some(sc) = binding(app, t) @@ -171,12 +196,13 @@ pub fn held_tool(app: &PhotocraftApp, ctx: &egui::Context) -> Option } cmd_move = cmd_move_held(app, i); alt = i.modifiers.alt; + hand = hand_zoom(app, i); }); // ⌥ turns a held Zoom In around, as it does the Zoom tool: ⌘⌥Space zooms out (and wins the // tie with ⌥Space), unless ⌥ is part of the Zoom In key itself. let held = best.map(|(_, t, sc)| if t == Temporary::ZoomIn && alt && !sc.modifiers.alt { Temporary::ZoomOut } else { t }); // A bound key (⌘Space is Zoom In) wins over ⌘ alone. - held.or(cmd_move.then_some(Temporary::Move)) + held.or(hand).or(cmd_move.then_some(Temporary::Move)) } /// The binding id of the Brush and Pencil erase key (`prefs::TEMPORARY_TOOLS`). diff --git a/crates/ui-egui/src/hold_keys/tests.rs b/crates/ui-egui/src/hold_keys/tests.rs index 706169face..d2bbc687ac 100644 --- a/crates/ui-egui/src/hold_keys/tests.rs +++ b/crates/ui-egui/src/hold_keys/tests.rs @@ -696,7 +696,9 @@ fn cmd_is_not_the_move_tool_for_selection_hand_zoom_pen_shape_or_type_tools() { let mut h = harness(tool); h.event(Event::ModifiersChanged(platform(Modifiers::COMMAND))); h.run_steps(1); - assert_eq!(held_tool(h.state(), &h.ctx), None, "{tool:?}"); + // The Hand's own ⌘ is Zoom In (#6434). + let want = (tool == Tool::Hand).then_some(Temporary::ZoomIn); + assert_eq!(held_tool(h.state(), &h.ctx), want, "{tool:?}"); } for tool in [Tool::Brush, Tool::Eraser, Tool::Gradient, Tool::CloneStamp, Tool::Eyedropper, Tool::MagneticLasso, Tool::QuickSelection] { assert!(cmd_moves(tool), "{tool:?}"); @@ -849,3 +851,157 @@ fn a_held_key_keeps_a_pending_crop_and_another_tools_key_commits_it() { assert_eq!(h.state().session.active().unwrap().doc.size, photocraft_doc::Size::new(200, 150)); assert_eq!(h.state().ui.crop_rect, None); } + +/// #6434: with the Hand tool selected, ⌘ (Ctrl off the Mac) held is Zoom In and ⌥ (with or +/// without ⌘) Zoom Out, as in Photoshop; letting go gives the Hand back. +#[test] +fn cmd_and_alt_with_the_hand_tool_zoom_in_and_out() { + let mut h = harness(Tool::Hand); + let z0 = h.state().ui.views[0].zoom; + hold_mods(&mut h, Modifiers::COMMAND); + assert_eq!(held_tool(h.state(), &h.ctx), Some(Temporary::ZoomIn)); + click(&mut h, 200.0, 150.0, Modifiers::COMMAND); + let z1 = h.state().ui.views[0].zoom; + assert!(z1 > z0, "{z0} -> {z1}"); + hold_mods(&mut h, Modifiers::NONE); + assert_eq!(held_tool(h.state(), &h.ctx), None); + + hold_mods(&mut h, Modifiers::ALT); + assert_eq!(held_tool(h.state(), &h.ctx), Some(Temporary::ZoomOut)); + click(&mut h, 200.0, 150.0, Modifiers::ALT); + let z2 = h.state().ui.views[0].zoom; + assert!(z2 < z1, "{z1} -> {z2}"); + hold_mods(&mut h, Modifiers::COMMAND | Modifiers::ALT); + assert_eq!(held_tool(h.state(), &h.ctx), Some(Temporary::ZoomOut)); + click(&mut h, 200.0, 150.0, Modifiers::COMMAND | Modifiers::ALT); + assert!(h.state().ui.views[0].zoom < z2); + hold_mods(&mut h, Modifiers::NONE); + assert_eq!(held_tool(h.state(), &h.ctx), None); + assert_eq!(h.state().ui.tool, Tool::Hand, "the Hand is still the tool"); +} + +/// A ⌘-drag with the Hand is the Zoom tool's scrubby zoom, not a pan. +#[test] +fn cmd_drag_with_the_hand_tool_is_a_scrubby_zoom() { + let mut h = harness(Tool::Hand); + let z0 = h.state().ui.views[0].zoom; + drag_with(&mut h, Modifiers::COMMAND, 200.0, 150.0, 300.0, 150.0); + assert!(h.state().ui.views[0].zoom > z0 * 1.5, "{z0} -> {}", h.state().ui.views[0].zoom); + assert_eq!(h.state().ui.tool, Tool::Hand); +} + +/// ⌘ or ⌥ pressed during a Hand pan doesn't turn the drag into a zoom: the pan goes on. +#[test] +fn modifiers_pressed_during_a_hand_pan_keep_panning() { + for m in [Modifiers::COMMAND, Modifiers::ALT] { + let mut h = harness(Tool::Hand); + let (z0, c0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center); + press_at(&mut h, 200.0, 150.0); + hold_mods(&mut h, m); + assert_eq!(held_tool(h.state(), &h.ctx), None, "{m:?}"); + let p = screen(&h, 200.0, 150.0) + vec2(60.0, 40.0); + h.event(Event::PointerMoved(p)); + h.run_steps(2); + button(&mut h, p, false, m); + hold_mods(&mut h, Modifiers::NONE); + let v = &h.state().ui.views[0]; + assert_eq!(v.zoom, z0, "{m:?}: no zoom"); + assert!(v.center[0] < c0[0] - 30.0 && v.center[1] < c0[1] - 20.0, "{m:?}: panned {c0:?} -> {:?}", v.center); + } +} + +/// A middle-button pan with the Hand selected keeps panning when ⌘ or ⌥ goes down during it. +#[test] +fn modifiers_pressed_during_a_middle_button_pan_keep_panning() { + for m in [Modifiers::COMMAND, Modifiers::ALT] { + let mut h = harness(Tool::Hand); + let (z0, c0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center); + let p = screen(&h, 200.0, 150.0); + h.event(Event::PointerMoved(p)); + h.run_steps(1); + h.event(Event::PointerButton { pos: p, button: PointerButton::Middle, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + hold_mods(&mut h, m); + assert_eq!(held_tool(h.state(), &h.ctx), None, "{m:?}"); + let q = p + vec2(60.0, 40.0); + h.event(Event::PointerMoved(q)); + h.run_steps(2); + h.event(Event::PointerButton { pos: q, button: PointerButton::Middle, pressed: false, modifiers: platform(m) }); + h.run_steps(1); + hold_mods(&mut h, Modifiers::NONE); + let v = &h.state().ui.views[0]; + assert_eq!(v.zoom, z0, "{m:?}: no zoom"); + assert!(v.center[0] < c0[0] - 30.0 && v.center[1] < c0[1] - 20.0, "{m:?}: panned {c0:?} -> {:?}", v.center); + } +} + +/// Free Transform keeps ⌘ (its distort handles) while the Hand is selected. +#[test] +fn cmd_with_the_hand_tool_is_not_a_zoom_during_free_transform() { + let mut h = harness(Tool::Hand); + with_layer(&mut h); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransform", json!({})).unwrap(); + h.run_steps(2); + assert!(h.state().ui.transform.is_some()); + hold_mods(&mut h, Modifiers::COMMAND); + assert_eq!(held_tool(h.state(), &h.ctx), None); +} + +/// The Modifier Keys panel's latched ⌥ and ⌘ count, for desktops that take Alt+click. +#[test] +fn latched_modifier_keys_zoom_with_the_hand_tool() { + let mut h = harness(Tool::Hand); + h.state_mut().ui.shell.sticky_command = true; + h.run_steps(1); + assert_eq!(held_tool(h.state(), &h.ctx), Some(Temporary::ZoomIn)); + h.state_mut().ui.shell.sticky_alt = true; + h.run_steps(1); + assert_eq!(held_tool(h.state(), &h.ctx), Some(Temporary::ZoomOut)); + h.state_mut().ui.shell = Default::default(); + h.state_mut().ui.tool = Tool::Brush; + h.state_mut().ui.shell.sticky_alt = true; + h.run_steps(1); + assert_eq!(held_tool(h.state(), &h.ctx), None, "only the Hand's ⌥ zooms"); +} + +/// A Hand press made without a modifier stays the Hand through its release: ⌘ or ⌥ pressed +/// before letting go (without moving past the drag threshold) doesn't zoom on the release. +#[test] +fn modifiers_pressed_before_a_hand_click_is_released_do_not_zoom() { + for m in [Modifiers::COMMAND, Modifiers::ALT] { + let mut h = harness(Tool::Hand); + let (z0, c0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center); + let p = screen(&h, 200.0, 150.0); + h.event(Event::PointerMoved(p)); + h.run_steps(1); + button(&mut h, p, true, Modifiers::NONE); + hold_mods(&mut h, m); + button(&mut h, p, false, m); + h.run_steps(1); + let v = &h.state().ui.views[0]; + assert_eq!((v.zoom, v.center), (z0, c0), "{m:?}: the release didn't zoom"); + // The modifier still zooms the next click. + click(&mut h, 200.0, 150.0, m); + assert_ne!(h.state().ui.views[0].zoom, z0, "{m:?}"); + hold_mods(&mut h, Modifiers::NONE); + } +} + +/// A click whose press and release arrive in one frame, with ⌘ held, still zooms. +#[test] +fn a_one_frame_cmd_click_with_the_hand_tool_zooms() { + let mut h = harness(Tool::Hand); + let z0 = h.state().ui.views[0].zoom; + hold_mods(&mut h, Modifiers::COMMAND); + let p = screen(&h, 200.0, 150.0); + h.event(Event::PointerMoved(p)); + h.run_steps(1); + let m = platform(Modifiers::COMMAND); + h.input_mut().events.extend([ + Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: m }, + Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: m }, + ]); + h.run_steps(2); + assert!(h.state().ui.views[0].zoom > z0); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index be1dfc2ba2..e491b01097 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity: tools, handles, modifiers and feel -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (the wheel steps value fields, #5473; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; a dragged guide shows its X or Y beside the pointer, #7680; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; a dragged guide shows its X or Y beside the pointer, #7680; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026 How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation, @@ -170,6 +170,8 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme | Behaviour | Status | Evidence | |---|---|---| | Space = Hand, ⌘Space / ⌘⌥Space = zoom in/out, spring-loaded while held | done | `hold_keys.rs` | +| Hand tool: ⌘ held = Zoom In, ⌥ (or ⌘⌥) held = Zoom Out; click steps, drag scrubs | done | `hold_keys.rs` `hand_zoom` (#6434); not during Free Transform or once a pan has started | +| Hand tool: ⇧-drag / Scroll All Windows pans every open document; hold H for Bird's Eye View | missing | | | Hold any tool letter for a temporary tool | done | `spring_tools.rs`: held ≥ 300 ms or used on the canvas, release gives the previous tool back; ⇧ never springs (#2672) | | Scrubby zoom | done | `zoom_tool.rs` | | Flick panning | done | `flick_pan.rs` (Preferences › Tools › Enable Flick Panning) | @@ -232,6 +234,7 @@ Paragraph; the rest open as in-app floating windows. |---|---|---| | 2026-10-19 | minor | A guide being moved or dragged out of a ruler shows an `X:` / `Y:` position readout beside the pointer, from the zero point in the ruler unit (#7680) | | 2026-10-17 | minor | The wheel steps value fields: a focused field takes it wherever the pointer is (the canvas and panels don't scroll), an unfocused one only a gesture that starts over it (#5473, #4061); no percentage changed | +| 2026-10-16 | minor | Hand tool ⌘ / ⌥ held are temporary Zoom In / Zoom Out (#6434); Scroll All Windows and Bird's Eye View rows added as missing | | 2026-10-15 | minor | Shape Density and Feather row added as done (TOOL-214-12, #5846) | | 2026-10-13 | minor | Menu bar from the keyboard: Alt / F10 focus, Alt+letter, underlined mnemonics (#4988) | | 2026-10-13 | minor | Layers panel filter row: Kind is a real dropdown with Kind, Name and Mode filters, drivable by `ui.set {layerFilter}` (#5048); row added as partial |