From 4f9023d80fdb9b5dfdd8bf6fe10c8e3311c303c0 Mon Sep 17 00:00:00 2001 From: Marco Arnulfo Date: Thu, 15 Oct 2026 19:04:53 +0200 Subject: [PATCH] Cmd/Ctrl+= and - zoom the canvas only, not the whole interface (fixes #580) --- crates/ui-egui/src/lib.rs | 3 +++ crates/ui-egui/src/shortcut_keys_tests.rs | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 9f166dfa..bf72ad78 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -902,6 +902,9 @@ impl FigApp { self.language = Some(self.session.prefs.language.clone()); } if !self.fonts_installed { + // Cmd/Ctrl+= / - / 0 zoom the canvas (view.zoomIn, view.zoomOut, view.zoom100): egui's + // own keyboard zoom would scale the whole interface on the same keys. + ctx.options_mut(|o| o.zoom_with_keyboard = false); theme::install_fonts(ctx, false, 0); self.fonts_installed = true; } else if figcraft_text::system_fonts_scanned() { diff --git a/crates/ui-egui/src/shortcut_keys_tests.rs b/crates/ui-egui/src/shortcut_keys_tests.rs index 4d1e5e85..42413a4f 100644 --- a/crates/ui-egui/src/shortcut_keys_tests.rs +++ b/crates/ui-egui/src/shortcut_keys_tests.rs @@ -2,7 +2,8 @@ //! headless: arrows pan with nothing selected, the keyboard box selection key and Cmd/Ctrl+arrows //! drawing it out, list indentation while editing text, symbols another keyboard layout types with //! Shift, the presentation keys (Space and N forward, C comments, F full screen), Alt+R for the -//! rotation origin and Enter placing a shape with its tool chosen. +//! rotation origin, Enter placing a shape with its tool chosen and Cmd/Ctrl+= and - zooming the +//! canvas, not the interface. use egui::{Event, Key, Modifiers, ViewportCommand, ViewportId}; use figcraft_doc::NodeId; @@ -211,3 +212,19 @@ fn full_screen_key_and_command_toggle_the_window() { u.app.run("view.fullscreen", json!({"on": "yes"})); u.frame(vec![]); } + +#[test] +fn cmd_plus_and_minus_zoom_the_canvas_not_the_interface() { + let mut u = Ui::new(Session::new()); + u.app.run("view.set", json!({"zoom": 1.0, "cx": 0, "cy": 0})); + press(&mut u, Key::Equals, cmd()); + // egui applies a new zoom factor at the start of the next frame. + u.frame(vec![]); + assert!(view(&u).2 > 1.0, "Cmd/Ctrl+= zooms the canvas in: {}", view(&u).2); + assert_eq!(u.ctx.zoom_factor(), 1.0, "and leaves the interface at its size"); + press(&mut u, Key::Minus, cmd()); + press(&mut u, Key::Minus, cmd()); + u.frame(vec![]); + assert!(view(&u).2 < 1.0, "Cmd/Ctrl+- zooms the canvas out: {}", view(&u).2); + assert_eq!(u.ctx.zoom_factor(), 1.0); +}