From 0d8d4b75d2761aafdfec0d2e4fc82ff9e981d42d Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 01:32:58 +0000 Subject: [PATCH] Claim Alt+1..9 for the Quick Access Toolbar on the document canvas; test that window keys reach the app --- crates/ui-egui/src/framework.rs | 26 +++++++++++++++++++++----- crates/ui-egui/src/tests.rs | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/framework.rs b/crates/ui-egui/src/framework.rs index 6dc8fc4f4..fb02ebdfe 100644 --- a/crates/ui-egui/src/framework.rs +++ b/crates/ui-egui/src/framework.rs @@ -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); } diff --git a/crates/ui-egui/src/tests.rs b/crates/ui-egui/src/tests.rs index 2073f959e..7dabe3fe3 100644 --- a/crates/ui-egui/src/tests.rs +++ b/crates/ui-egui/src/tests.rs @@ -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).