From 8cd51bf95a2ceca77b3e157ab3a63a718b7e89ef Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 21:28:31 -0800 Subject: [PATCH 1/2] Command Palette: "setting" finds Preferences, and a Recent Commands pick gives the focus back The stem forms of a group's English words join the group, so "setting" finds Preferences through settings. A pick from Recent Commands with the keyboard, which leaves the focus on its row, now gives the focus back to the widget that had it when the palette opened. --- crates/ui-egui/src/palette.rs | 52 ++++++++++++++++++++++++++-- crates/ui-egui/src/palette/search.rs | 28 +++++++++++---- 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 2ad2ffcea3..3330281587 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -569,16 +569,21 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { // closed it focused another widget, such as a field in a window above the backdrop. let focus_id = egui::Id::unique("palette-focus-before"); let field_id = egui::Id::unique("palette-field"); + // The Recent Commands rows drawn in the last frame, so a pick with the keyboard, which leaves the + // focus on its row, gives the focus back too. + let rows_id = egui::Id::unique("palette-recent-rows"); if !app.ui.palette_open { - let field = ctx.data_mut(|d| { + let (field, rows) = ctx.data_mut(|d| { let field = d.get_temp::(field_id); d.remove::(field_id); - field + let rows = d.get_temp::>(rows_id).unwrap_or_default(); + d.remove::>(rows_id); + (field, rows) }); let now = ctx.memory(|m| m.focused()); if let Some(Some(before)) = ctx.data_mut(|d| d.remove_temp::>(focus_id)) && app.ui.dialog.is_none() - && (now.is_none() || now == field) + && (now.is_none() || now == field || now.is_some_and(|n| rows.contains(&n))) { ctx.memory_mut(|m| m.request_focus(before)); } @@ -701,12 +706,14 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { if !list_open && !history_focused { r.request_focus(); } + let mut rows = Vec::new(); egui::Popup::menu(&button).id(recent_list_id()).show(|ui| { if recent.is_empty() { ui.add_enabled(false, egui::Button::new(tl!("No recent commands"))); } for (i, e) in recent.iter().enumerate() { let row = ui.add(egui::Button::new(e.shown.as_str()).shortcut_text(menus::shown_shortcut(&e.shortcut))); + rows.push(row.id); if i == rsel { row.request_focus(); } @@ -715,6 +722,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } } }); + ui.ctx().data_mut(|d| d.insert_temp(rows_id, rows)); r }) .inner; @@ -2334,6 +2342,44 @@ mod tests { assert_eq!(ctx.memory(|m| m.focused()), Some(above), "the clicked field keeps the focus"); } + /// A pick with the keyboard from Recent Commands that opens no dialog gives the focus back to + /// the widget that had it when the palette opened, though the picked row had the keyboard. + #[test] + fn a_pick_from_recent_commands_gives_the_focus_back() { + let ctx = egui::Context::default(); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + app.ui.recent_commands = vec!["paint.swap".into()]; + let mut text = String::new(); + let field = egui::Id::unique("other field"); + let mut frame = |app: &mut VectorcraftApp, focus: bool, events: Vec| { + ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| { + let r = ui.add(egui::TextEdit::singleline(&mut text).id(field)); + if focus { + r.request_focus(); + } + show(app, ui.ctx()); + }) + .textures_delta + .clear(); + }; + frame(&mut app, true, vec![]); + frame(&mut app, false, vec![]); + app.ui.palette_open = true; + frame(&mut app, false, vec![]); + egui::Popup::open_id(&ctx, recent_list_id()); + frame(&mut app, false, vec![]); + frame(&mut app, false, vec![]); + assert!(recent_list_open(&ctx), "the list is open"); + assert_ne!(ctx.memory(|m| m.focused()), Some(field), "the row has the keyboard"); + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + frame(&mut app, false, vec![enter]); + assert!(!app.ui.palette_open, "the pick closes the palette"); + assert!(app.ui.dialog.is_none(), "{}", app.ui.status); + frame(&mut app, false, vec![]); + frame(&mut app, false, vec![]); + assert_eq!(ctx.memory(|m| m.focused()), Some(field)); + } + /// The whole window, with a document whose rectangle is selected, drawn a frame at a time in /// English with screen readers on. struct Window { diff --git a/crates/ui-egui/src/palette/search.rs b/crates/ui-egui/src/palette/search.rs index e70b9f3637..8f1dd0e504 100644 --- a/crates/ui-egui/src/palette/search.rs +++ b/crates/ui-egui/src/palette/search.rs @@ -72,8 +72,9 @@ pub(crate) struct Index { initials_text: String, /// Each result's offset and length in `initials_text`. initials: Vec<(u32, u16)>, - /// Each word of a group of words with the same meaning ([`super::words::GROUPS`], and the - /// words the UI language's catalog adds), with the group's place in the table. + /// Each word of a group of words with the same meaning ([`super::words::GROUPS`], the words the + /// UI language's catalog adds, and the English words' stem forms), with the group's place in the + /// table. synonyms: HashMap, u16>, } @@ -84,8 +85,10 @@ pub(crate) fn is_one_word(w: &str) -> bool { } /// The words of each group of [`super::words::GROUPS`], with the words `search_row` gives for the -/// group's catalog row ([`super::words::row_key`]) in the UI language. A word the catalog gives -/// that is not a single word, or that is already a word of a group, is left out. +/// group's catalog row ([`super::words::row_key`]) in the UI language, and the English stem forms +/// ([`stems`]) of the group's English words (`setting` of settings). A word the catalog gives that +/// is not a single word, or that is already a word of a group, is left out, and so is a stem form +/// that is already a word of a group. fn synonym_groups(search_row: impl Fn(&str) -> Option) -> HashMap, u16> { let mut out: HashMap, u16> = HashMap::new(); let groups = super::words::GROUPS.iter().enumerate().filter_map(|(g, words)| u16::try_from(g).ok().map(|g| (g, words))); @@ -94,7 +97,7 @@ fn synonym_groups(search_row: impl Fn(&str) -> Option) -> HashMap Option) -> HashMap Date: Wed, 18 Nov 2026 06:38:30 -0800 Subject: [PATCH 2/2] Command Palette: the catalog check reports a word two search rows add to different groups A catalog's search rows are now checked together: a word that two rows add to different groups fails the i18n test, naming the word and both groups. A word repeated for one group, and a catalog with no search rows, still pass. --- crates/ui-egui/src/i18n/tests.rs | 9 ++++---- crates/ui-egui/src/palette/words.rs | 33 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 1ef955c627..9e3cf16398 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -805,16 +805,15 @@ fn anti_aliasing_method_labels_are_in_complete_catalogs() { } /// Each row in the `search` context, which adds a language's words to a group of words with the same -/// meaning for the command palette, names a group and adds single words of no other group. No -/// catalog has to have these rows. +/// meaning for the command palette, names a group and adds single words of no other group, and no +/// two rows of a catalog add one word to different groups. No catalog has to have these rows. #[test] fn search_rows_name_a_group_and_add_single_words() { let mut bad = Vec::new(); for l in LANGUAGES.iter().filter(|l| !l.source.is_empty()) { let (entries, _) = parse_entries(l.source); - for (_, src, tr) in entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT) { - bad.extend(crate::palette::words::row_problems(src, tr).into_iter().map(|p| format!("{}: {p}", l.code))); - } + let rows = entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT).map(|(_, src, tr)| (src.as_str(), tr.as_str())); + bad.extend(crate::palette::words::catalog_problems(rows).into_iter().map(|p| format!("{}: {p}", l.code))); } assert!(bad.is_empty(), "{bad:#?}"); } diff --git a/crates/ui-egui/src/palette/words.rs b/crates/ui-egui/src/palette/words.rs index 44176dbd24..86c03bfb8c 100644 --- a/crates/ui-egui/src/palette/words.rs +++ b/crates/ui-egui/src/palette/words.rs @@ -91,6 +91,27 @@ pub(crate) fn row_problems(source: &str, text: &str) -> Vec { problems } +/// What is wrong with one catalog's `search` rows, each a group's `source` and its translation +/// `text`: each row's [`row_problems`], and a word that rows add to two different groups. +#[cfg(test)] +pub(crate) fn catalog_problems<'a>(rows: impl IntoIterator) -> Vec { + let mut problems = vec![]; + let mut groups: std::collections::HashMap = std::collections::HashMap::new(); + for (source, text) in rows { + problems.extend(row_problems(source, text)); + for (w, _) in row_words(text).filter(|(_, single)| *single) { + match groups.get(w.as_str()) { + Some(&first) if first != source => problems.push(format!("{w:?} is a word of {first:?} and {source:?}")), + Some(_) => {} + None => { + groups.insert(w, source); + } + } + } + } + problems +} + #[cfg(test)] mod tests { use super::*; @@ -122,4 +143,16 @@ mod tests { assert_eq!(row_problems("remove, delete, erase, clear", "ganz entfernen").len(), 1, "two words"); assert_eq!(row_problems("remove, delete, erase, clear", "Text").len(), 1, "a word of another group once lowercased"); } + + /// A catalog's rows fail when they add one word to two groups, and pass when a word is repeated + /// for one group or the catalog has no rows. + #[test] + fn a_word_in_two_groups_of_a_catalog_is_checked() { + let (remove, artboard) = ("remove, delete, erase, clear", "artboard, canvas"); + let problems = catalog_problems([(remove, "retrait"), (artboard, "plan, Retrait")]); + assert_eq!(problems.len(), 1, "{problems:?}"); + assert!(problems.iter().all(|p| p.contains("retrait") && p.contains(remove) && p.contains(artboard)), "{problems:?}"); + assert!(catalog_problems([(remove, "retrait, retrait"), (remove, "Retrait"), (artboard, "plan")]).is_empty()); + assert!(catalog_problems([]).is_empty()); + } }