fix(keytips): open Search on Alt/F10, Q when Backstage is closed (#7750) (#7619)

This commit is contained in:
Lucas Batista Vargas
2026-11-26 21:02:19 +00:00
committed by GitHub
parent 257b81ec8f
commit 5d2153c15d
2 changed files with 72 additions and 1 deletions
+19 -1
View File
@@ -142,6 +142,24 @@ fn legacy() -> &'static [(&'static str, CommandRef)] {
})
}
/// Cached `Phase::Tabs` keytip sequences (`SEARCH_LETTER` when Backstage is closed, plus Word
/// 2003 legacy menu keys on non-macOS).
fn sequences(backstage: bool) -> &'static [(&'static str, CommandRef)] {
static WITH_SEARCH: OnceLock<Vec<(&'static str, CommandRef)>> = OnceLock::new();
static SEARCH_ONLY: OnceLock<[(&'static str, CommandRef); 1]> = OnceLock::new();
match (cfg!(target_os = "macos"), backstage) {
(true, true) => &[],
(true, false) => SEARCH_ONLY.get_or_init(|| [(SEARCH_LETTER, CommandRef::new("tools.search"))]),
(false, true) => legacy(),
(false, false) => WITH_SEARCH.get_or_init(|| {
let mut v = legacy().to_vec();
v.push((SEARCH_LETTER, CommandRef::new("tools.search")));
v
}),
}
}
/// The letter badge for a tab (empty when it has none).
pub fn tab_letter(tab: &str) -> &'static str {
TAB_LETTERS.iter().chain(&TABLE_TAB_LETTERS).find(|(t, _)| *t == tab).map(|(_, l)| *l).unwrap_or("")
@@ -526,7 +544,7 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
None => KeytipCache::new(app, &app.ui.tab),
};
let controls: &[KeytipControl<'_>] = if app.ui.backstage { backstage_controls() } else { &cache.tab_controls };
let sequences: &[(&str, CommandRef)] = if cfg!(target_os = "macos") { &[] } else { legacy() };
let sequences = sequences(app.ui.backstage);
// A hidden toolbar has no badges, and a disabled command's button has none to press.
let digits: Vec<CommandRef> = if app.ui.quick_access_toolbar {
app.session
+53
View File
@@ -397,6 +397,59 @@ fn long_qat_badges_wait_for_the_complete_number_and_escape_cancels() {
}
}
/// #819: Alt (or F10), then Q opens Search in the title bar, ends keytips, and never types into
/// the document; while the Backstage is open, Q does not open Search.
#[test]
fn alt_then_q_opens_search() {
let mut h = harness(app());
assert!(!crate::chrome::search::is_open(h.state()), "Search starts closed");
// F10, then Q works on every platform (including macOS, where bare Option types characters).
h.input_mut().events.push(key_event(egui::Key::F10, true, egui::Modifiers::NONE));
crate::test_harness::frame(&mut h);
assert!(h.state().keytips_active, "F10 activates keytips");
h.input_mut().events.extend([key_event(egui::Key::Q, true, egui::Modifiers::NONE), egui::Event::Text("q".into())]);
crate::test_harness::frames(&mut h, 2);
assert!(!h.state().keytips_active, "Q ends keytips");
assert!(crate::chrome::search::is_open(h.state()), "F10, Q opens Search");
assert!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body).is_empty(), "Q does not type into the document");
// On non-macOS, a bare Alt tap followed by Q opens Search without typing into the document.
if !cfg!(target_os = "macos") {
h.state_mut().chrome.search = false;
let ctx = h.ctx.clone();
h.state_mut().canvas.focus_page(&ctx);
crate::test_harness::frame(&mut h);
let alt = egui::Modifiers { alt: true, ..Default::default() };
h.input_mut().events.extend([key_event(egui::Key::AltLeft, true, egui::Modifiers::NONE), egui::Event::ModifiersChanged(alt)]);
crate::test_harness::frame(&mut h);
h.input_mut().events.extend([key_event(egui::Key::AltLeft, false, alt), egui::Event::ModifiersChanged(egui::Modifiers::NONE)]);
crate::test_harness::frame(&mut h);
assert!(h.state().keytips_active, "a bare Alt tap activates keytips");
h.input_mut().events.extend([key_event(egui::Key::Q, true, egui::Modifiers::NONE), egui::Event::Text("q".into())]);
crate::test_harness::frames(&mut h, 2);
assert!(!h.state().keytips_active, "Q ends keytips after bare Alt");
assert!(crate::chrome::search::is_open(h.state()), "Alt, Q opens Search");
assert!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body).is_empty(), "Alt, Q does not type into the document");
}
// With Backstage open, Q does not open Search behind it.
h.state_mut().chrome.search = false;
h.state_mut().run("ui.backstage", serde_json::json!({"value": true})).unwrap();
crate::test_harness::frame(&mut h);
assert!(h.state().ui.backstage, "Backstage is open");
h.input_mut().events.push(key_event(egui::Key::F10, true, egui::Modifiers::NONE));
crate::test_harness::frame(&mut h);
h.input_mut().events.extend([key_event(egui::Key::Q, true, egui::Modifiers::NONE), egui::Event::Text("q".into())]);
crate::test_harness::frames(&mut h, 2);
assert!(!crate::chrome::search::is_open(h.state()), "Q does not open Search while Backstage is open");
assert!(h.state().dialog_host.open_dialogs().is_empty(), "Q does not open the Search dialog while Backstage is open");
}
#[test]
fn qat_keytips_follow_custom_order_and_skip_disabled_commands() {
let mut a = app();