From d6497ecebb2b7e5a7d56a14f853b69d79ecbab84 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Mon, 30 Nov 2026 23:47:51 -0800 Subject: [PATCH] View: keep Cmd+0 on Fit Artboard in Window --- crates/ui-egui/src/menus/model.rs | 5 ++++- crates/ui-egui/src/shortcuts/tests.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/menus/model.rs b/crates/ui-egui/src/menus/model.rs index 73a4296dd9..0d485aa36a 100644 --- a/crates/ui-egui/src/menus/model.rs +++ b/crates/ui-egui/src/menus/model.rs @@ -447,7 +447,10 @@ fn build_catalog(app: &VectorcraftApp, listed: &Listed, plays: &[(String, craft: Ok(catalog) => { // While a text field has the keys no shortcut runs, as in production; the text-editing chords still edit it, // and the Type tool's commands run while it types. - let catalog = catalog.typing_rule(TypingRule::AllWait); + // The document canvas also defaults to Cmd+0, but its Fit on Screen stops at actual size. + // Leave that chord to VectorCraft's Fit Artboard in Window. + let fit_on_screen = CommandRef::from(craft::ui::canvas::ViewCommands::FitOnScreen); + let catalog = catalog.typing_rule(TypingRule::AllWait).replace_defaults(fit_on_screen.id, Vec::new()); let catalog = linked_keys.into_iter().fold(catalog, |catalog, (id, keys)| catalog.replace_defaults(id, keys)); let catalog = UNROUTED.iter().fold(catalog, |catalog, id| catalog.replace_defaults(id.as_str(), Vec::new())); Some(type_keys.into_iter().fold(catalog, |catalog, (id, keys)| catalog.replace_defaults(id, keys))) diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index d22d8e9eb6..6a4e4fb098 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -80,6 +80,33 @@ fn idle(app: &mut VectorcraftApp, ctx: &egui::Context, n: usize) { } } +/// A focused document canvas must use the app's artboard fit, whose zoom may exceed 100%. +#[test] +fn command_zero_fits_the_active_artboard_when_the_canvas_has_focus() { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 120, "height": 80, "artboards": 2})).unwrap(); + app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": false})).unwrap(); + let ctx = ready(&mut app); + app.view_mut().unwrap().artboard = 1; + + app.run("view.fitArtboard", json!({})).unwrap(); + idle(&mut app, &ctx, 12); + let fitted = app.view().unwrap(); + let (zoom, center) = (fitted.zoom, fitted.center); + assert!(zoom > 1.0, "this artboard has room to grow past actual size: {zoom}"); + + app.run("view.setZoom", json!({"zoom": 50})).unwrap(); + idle(&mut app, &ctx, 12); + focus_canvas(&mut app, &ctx); + assert!(app.view().unwrap().zoom < 1.0); + key_frame(&mut app, &ctx, tap(Key::Num0, cmd())); + idle(&mut app, &ctx, 12); + + let fitted = app.view().unwrap(); + assert!((fitted.zoom - zoom).abs() < 1e-6, "shortcut zoom {} should match the menu fit {zoom}", fitted.zoom); + assert_eq!(fitted.center, center, "fit the active artboard, not the whole document"); +} + /// An app with a 200 × 200 document whose window has drawn its first frame, which builds the keymap the shortcut /// commands edit. fn new_app() -> VectorcraftApp {