Claim Alt+1..9 for the Quick Access Toolbar on the document canvas; test that window keys reach the app

This commit is contained in:
aiongg committed 2026-11-24 01:32:58 +00:00
1 parent bfdca1cecd
commit 0d8d4b75d2
2 files changed
+39 -5

No files matched your search

+21 -5
View File
@@ -12,7 +12,7 @@ use std::sync::{Arc, OnceLock};
use craft_host::target::ShellInfo;
use craft_host::{AppInfo, Host};
use craft_keymap::Overrides;
use craft_keymap::{Chord, Key, Mods, Overrides};
use craft_ui::fonts::{I18nScripts, SystemFonts, UiFonts};
use craft_ui::runtime::commands::{CommandInput, CommandSet, NavCommand};
use craft_ui::runtime::env::{RootEnv, Scale};
@@ -117,12 +117,28 @@ impl SlideApp {
}
}
/// The keys DeckCraft's document window keeps while it is the window's key target: Tab (indent, next shape) and
/// every clipboard event and edit chord, which `SlideApp::keyboard` routes itself.
const DOCUMENT_KEYS: KeyUse = KeyUse::CANVAS.with_keep(KeepKeys::Tab).with_edits(EditSet::ALL);
/// Alt+1 to Alt+9, the Quick Access Toolbar's positions on Windows and Linux (`menus::ui_shortcut`). Claimed, so
/// the runtime's Alt+numpad code entry leaves them to DeckCraft's shortcuts.
const QUICK_ACCESS_KEYS: [Chord; 9] = [
Chord::new(Mods::ALT, Key::Num1),
Chord::new(Mods::ALT, Key::Num2),
Chord::new(Mods::ALT, Key::Num3),
Chord::new(Mods::ALT, Key::Num4),
Chord::new(Mods::ALT, Key::Num5),
Chord::new(Mods::ALT, Key::Num6),
Chord::new(Mods::ALT, Key::Num7),
Chord::new(Mods::ALT, Key::Num8),
Chord::new(Mods::ALT, Key::Num9),
];
/// The keys DeckCraft's document window keeps while it is the window's key target: Tab (indent, next shape),
/// every clipboard event and edit chord, and the Quick Access Toolbar's Alt+digits, which `SlideApp::keyboard`
/// routes itself.
const DOCUMENT_KEYS: KeyUse = KeyUse::CANVAS.with_keep(KeepKeys::Tab).with_edits(EditSet::ALL).with_claims(&QUICK_ACCESS_KEYS);
/// Declares DeckCraft's document window, drawn in this pass, as the window's canvas. With nothing focused it is the
/// window's key target, so Tab, the edit chords and the clipboard events stay in egui's input for DeckCraft.
/// window's key target, so Tab, the edit chords, the clipboard events and the claimed Alt+digits stay in egui's input
/// for DeckCraft.
pub(crate) fn host_canvas(ctx: &egui::Context) {
craft_ui::runtime::focus::host_canvas(ctx, egui::Id::unique("deckcraft_document"), DOCUMENT_KEYS);
}
+18
View File
@@ -1013,6 +1013,24 @@ fn harness() -> egui_kittest::Harness<'static, SlideApp> {
)
}
/// With the framework runtime installed, the window's keys still reach DeckCraft's own routing: Alt+1 runs the
/// first Quick Access Toolbar item (Alt+numpad code entry leaves the claimed chord alone off macOS), and Escape with
/// nothing focused leaves the File tab.
#[test]
fn alt_digit_and_escape_reach_the_app_through_the_runtime() {
let mut h = harness();
h.state_mut().run("file.new", json!({})).unwrap();
h.state_mut().session.mac_keys = false;
h.run_steps(3);
assert!(!h.state().backstage_open());
h.key_press_modifiers(egui::Modifiers::ALT, egui::Key::Num1);
h.run_steps(2);
assert!(h.state().backstage_open(), "Alt+1 runs app.home, which opens the File tab");
h.key_press(egui::Key::Escape);
h.run_steps(2);
assert!(!h.state().backstage_open(), "Escape leaves the File tab");
}
/// #172: a recent file that no longer exists is marked on File › Home, and clicking it draws
/// the open error right there (the status bar is hidden while the backstage is open, so the
/// message used to vanish).