Cmd/Ctrl+= and - zoom the canvas only, not the whole interface (fixes #580)

This commit is contained in:
Marco Arnulfo
2026-10-15 19:04:53 +02:00
parent 102404e8c3
commit 4f9023d80f
2 changed files with 21 additions and 1 deletions
+3
View File
@@ -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() {
+18 -1
View File
@@ -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);
}