diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index fdbd7dcb2f8..cd5f221a647 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -885,7 +885,7 @@ pub fn menu_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> f32 { if top == "Help" { // The search field scrolls with the rows, as part of the menu's content. crate::menu_nav::level(ui, 1, &mut nav, |ui, nav| { - help_search(ui, items, &mut clicked, nav); + help_search(ui, items, opening, &mut clicked, nav); render_level_rows(ui, &mine, 1, &mut clicked, nav); }); } else { @@ -1014,7 +1014,8 @@ pub fn search_items<'a>(items: &'a [MenuItem], query: &str, lang: crate::i18n::L /// Help › Search : a field at the top of the Help menu that finds any menu command /// by name. Results show their menu path; click, ↓ then ↩, or ↩ in the field runs one. -fn help_search(ui: &mut egui::Ui, items: &[MenuItem], clicked: &mut Option, nav: &mut crate::menu_nav::Nav) { +/// `opening`: this frame's release ends the click on the Help title that opened the menu. +fn help_search(ui: &mut egui::Ui, items: &[MenuItem], opening: bool, clicked: &mut Option, nav: &mut crate::menu_nav::Nav) { let ctx = ui.ctx().clone(); let lang = crate::i18n::current(); let text_id = egui::Id::new("help-menu-search"); @@ -1025,7 +1026,9 @@ fn help_search(ui: &mut egui::Ui, items: &[MenuItem], clicked: &mut Option, at: egui::Pos2| { + h.event(Event::PointerMoved(at)); + h.run_steps(1); + h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(3); + }; + let typing = |h: &mut Harness<'_, PhotocraftApp>, text: &str| { + for c in text.chars() { + h.event(Event::Text(c.to_string())); + h.run_steps(1); + } + h.run_steps(3); + }; + let open = |h: &Harness<'_, PhotocraftApp>| h.query_by_label_contains("About PhotoCraft").is_some(); + let field_id = egui::Id::new("help-menu-search").with("field"); + let help = h.get_by_label("Help").rect().center(); + click(&mut h, help); + assert!(open(&h), "Help opened ({what})"); + assert_eq!(h.ctx.memory(|m| m.focused()), Some(field_id), "the click on Help leaves the search field focused ({what})"); + typing(&mut h, "lev"); + assert!(open(&h), "typing keeps Help open ({what})"); + assert!(h.query_all_by_label_contains("› Levels").next().is_some(), "typing right away searches ({what})"); + let field = h.query_all_by_role(egui::accesskit::Role::TextInput).find(|n| n.is_focused()).map(|n| n.rect().center()); + let field = field.unwrap_or_else(|| panic!("the search field is in the accessibility tree ({what})")); + click(&mut h, field); + assert!(open(&h), "clicking the search field keeps Help open ({what})"); + assert_eq!(h.ctx.memory(|m| m.focused()), Some(field_id), "and focused ({what})"); + typing(&mut h, "els"); + assert!(open(&h), "typing after the click keeps Help open ({what})"); + assert!(h.query_all_by_label_contains("› Levels").next().is_some(), "and lists the matches ({what})"); + } + } + #[test] fn dropdown_items_have_room() { use egui_kittest::{Harness, kittest::Queryable};