LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
KEY-TOGGLEZOOM: Toggle Zoom bound to Space in the keymap takes the hand and toggles once
helgehelge123c9c3870ab387
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rsindex 3dbf680f6..6a9e19a4f 100644--- a/crates/ui-egui/src/shortcuts.rs+++ b/crates/ui-egui/src/shortcuts.rs@@ -393,6 +393,8 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {{fire.push("view.detail".to_string());}+ // a held Space repeats: it toggles the zoom (or takes the hand) once per press+ let space_repeat = !i.events.iter().any(|e| matches!(e, egui::Event::Key { key: Key::Space, pressed: true, repeat: false, .. }));for b in bindable() {if let Some(sc) = binding(keymap, b.id, b.default)&& let Some((m, k)) = parse(sc)@@ -401,11 +403,17 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {&& matches(i, m, k)&& let Some(id) = grid_key_command(keymap, grid, app.ui.fullscreen, b.id, (m, k)){- fire.push(id.to_string());+ if id == "view.zoomToggle" && k == Key::Space {+ // Toggle Zoom given Space in the keymap is the Space alias: the same hand and+ // the same once-per-press+ if !space_repeat {+ aliased.push(("view.zoomToggle", json!({})));+ }+ } else {+ fire.push(id.to_string());+ }}}- // a held Space repeats: it toggles the zoom (or takes the hand) once per press- let space_repeat = !i.events.iter().any(|e| matches!(e, egui::Event::Key { key: Key::Space, pressed: true, repeat: false, .. }));for (sc, id, params) in ALIASES {if let Some((m, k)) = parse(sc).filter(|_| !native(sc))&& !(k == Key::Escape && popup_open)diff --git a/crates/ui-egui/src/tests_space_hand.rs b/crates/ui-egui/src/tests_space_hand.rsindex 701408e34..02c90705b 100644--- a/crates/ui-egui/src/tests_space_hand.rs+++ b/crates/ui-egui/src/tests_space_hand.rs@@ -106,6 +106,29 @@ fn a_held_space_toggles_the_zoom_once_however_long_it_repeats() {assert_eq!(h.app.ui.zoom, Zoom::Fit);}+#[test]+fn toggle_zoom_given_space_in_the_keymap_takes_the_hand_and_toggles_once() {+ // with Space as Toggle Zoom's own shortcut the Space alias yields to it: the binding gets the+ // same hand over a tool and the same once-per-press+ let mut h = detail(None);+ crate::shortcuts::assign(&mut h.app.ui.settings.keymap, "view.zoomToggle", Some("Space")).unwrap();+ space(&mut h, "down");+ assert_eq!(h.app.ui.zoom, Zoom::Percent(100.0));+ for _ in 0..3 {+ space(&mut h, "down");+ }+ assert_eq!(h.app.ui.zoom, Zoom::Percent(100.0), "a repeat toggled the zoom");+ space(&mut h, "up");+ let r = h.request("engine.execute", json!({"command": "panel.remove"}), T);+ assert_eq!(r["ok"], true, "{r}");+ h.step();+ zoom_in(&mut h);+ space(&mut h, "down");+ assert!(h.app.space_hand.is_some(), "the binding did not take the hand");+ assert_eq!(h.app.ui.zoom, Zoom::Percent(200.0), "the press zoomed");+ space(&mut h, "up");+}+#[test]fn space_held_over_the_healing_brush_pans_and_paints_no_spot() {let mut h = detail(Some("panel.remove"));