PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Hand tool: hold Ctrl/Cmd to zoom in, Alt to zoom out (#6434)
Khawar Zamman Wani21b8d832afd5
diff --git a/crates/ui-egui/src/hold_keys.rs b/crates/ui-egui/src/hold_keys.rsindex 3f2845cae..e492515e6 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,27 @@ 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).+fn hand_zoom(app: &PhotocraftApp, i: &InputState) -> Option<Temporary> {+ let p = &i.pointer;+ let hand_press = (p.primary_down() || p.primary_released()) && !p.primary_pressed();+ 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 +183,7 @@ pub fn held_tool(app: &PhotocraftApp, ctx: &egui::Context) -> Option<Temporary>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 +195,13 @@ pub fn held_tool(app: &PhotocraftApp, ctx: &egui::Context) -> Option<Temporary>}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.rsindex cfe89d464..e88ec917a 100644--- a/crates/ui-egui/src/hold_keys/tests.rs+++ b/crates/ui-egui/src/hold_keys/tests.rs@@ -643,7 +643,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:?}");@@ -796,3 +798,132 @@ 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);+ }+}++/// 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.mdindex 793f09840..4988aace5 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-15 · **Change:** minor (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) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-16 · **Change:** minor (Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; 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) · **Target:** Adobe Photoshop 2026How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, thehandles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,@@ -167,6 +167,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) |@@ -227,6 +229,7 @@ Paragraph; the rest open as in-app floating windows.| Date | Change | Summary ||---|---|---|+| 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-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 || 2026-10-13 | minor | Stale "missing tool" rows corrected against main: Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (the P flyout cycle) are live toolbar tools, so only Art History Brush is missing; no percentage or estimate changed |