mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 20:18:38 -05:00
View: keep Cmd+0 on Fit Artboard in Window
This commit is contained in:
1 parent
84335645da
commit
d6497ecebb
2 files changed
+31
-1
No files matched your search
@@ -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)))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user