From 6d9a603d9cfb7af4743b14dd5e6e2d7bee11005c Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 9 Oct 2026 02:13:24 +0200 Subject: [PATCH] =?UTF-8?q?Help=20=E2=80=BA=20Search:=20keep=20the=20field?= =?UTF-8?q?=20focused=20after=20a=20click=20opens=20Help=20(#1447,=20#1438?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both reports were filed against v0.5.0, which predates e63ff519 (#1027): there the Help menu used egui's CloseOnClick, so any click inside it, including on the search field, closed it. The egui menu bar is what Windows (and Linux) show; macOS uses the native menu bar, hence "on Windows". That close is fixed on main but not yet released. What remained on main: menus open on the press, and the search field asks for focus then, but the release a frame later completes a click on the Help title, outside the field, so egui (SurrenderFocusOn::Clicks) took the focus away again. After clicking Help, typing went nowhere until the field was clicked. The field now asks for focus again on that release, as on a fresh opening. The new whole-app kittest drives real clicks (press and release in separate frames) with and without the custom title bar and at 1.25x and 1.5x scale. It checks the field is focused after Help opens, that typing searches at once, and that clicking the field and typing keeps Help open. It fails without this change (focus) and with v0.5.0's CloseOnClick for Help (menu closes). Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/ui-egui/src/menus.rs | 65 +++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 36df56cc946..ea456a53b15 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -864,7 +864,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 { @@ -993,7 +993,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"); @@ -1004,7 +1005,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};