diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 2e33ef9cf8..8b2b35db16 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -463,7 +463,14 @@ impl CanvasTool for SessionTool<'_> { if claim(&mut app, EngineKey::Left) { claims = claims.nudges(); } - if claim(&mut app, EngineKey::AltTap) { + // A lone Alt while the canvas has the keys is the tools' modifier let go without a click: the canvas takes it, + // so it does not give the menu bar the keys and the next tool letter still chooses its tool. F10 and Alt with + // a letter still reach the bar, and a lone Alt in a field or the bar keeps the framework's rule. + let canvas_has_keys = app + .ui_ctx + .as_ref() + .is_some_and(|ctx| !ctx.egui_wants_keyboard_input() && !craft::ui::menu::bar::is_focused(ctx) && !craft::ui::menu::bar::is_open(ctx)); + if canvas_has_keys || claim(&mut app, EngineKey::AltTap) { claims = claims.alt_tap(); } claims diff --git a/crates/ui-egui/tests/menu_access_keys.rs b/crates/ui-egui/tests/menu_access_keys.rs index c837734c99..f2a04cd75a 100644 --- a/crates/ui-egui/tests/menu_access_keys.rs +++ b/crates/ui-egui/tests/menu_access_keys.rs @@ -164,10 +164,22 @@ fn menu_access_custom_shortcut_typing_tool_altgr_and_cancel_ownership() { assert_eq!(s.app.session.tool_id(), "pen", "after the dismissal the letter selects its tool"); s.app.select_tool("selection"); - // While the bar holds the keys after a lone Alt, the letter does not reach the tool either. + // A lone Alt over the canvas is a tool modifier let go: the bar does not take the keys, and the next tool + // letters choose their tools instead of opening View or Window. s.bare_alt(); s.settle(); - assert!(is_focused(&s.ctx), "a lone Alt gives the bar the keys"); + assert!(!is_focused(&s.ctx) && !is_open(&s.ctx), "a lone Alt over the canvas leaves the bar alone"); + s.letter(Key::V, "v", Modifiers::NONE); + assert!(!is_open(&s.ctx), "V after a lone Alt opens no menu"); + s.letter(Key::P, "p", Modifiers::NONE); + assert_eq!(s.app.session.tool_id(), "pen", "P after a lone Alt chooses the Pen"); + s.app.select_tool("selection"); + + // While the bar holds the keys after F10, the letter does not reach the tool. + s.frame(vec![key(Key::F10, true, Modifiers::NONE)]); + s.frame(vec![key(Key::F10, false, Modifiers::NONE)]); + s.settle(); + assert!(is_focused(&s.ctx), "F10 gives the bar the keys"); s.letter(Key::P, "p", Modifiers::NONE); assert_eq!(s.app.session.tool_id(), "selection", "a focused bar takes the letter"); s.click(outside);