From 8cc6b074b9fe77c6af9aa442ccac35d5434efcee Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 06:16:55 -0800 Subject: [PATCH] Command Palette: a word two search rows of one catalog add is reported The i18n test of the `search` rows now also checks that no two rows of one catalog add the same word. Such a word was given to only the first row's group, so a search for it did not find results through the other group. --- crates/ui-egui/src/i18n/tests.rs | 9 +++++--- crates/ui-egui/src/palette/words.rs | 33 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 1ef955c627..46805d66dc 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -805,16 +805,19 @@ 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 one catalog add the same word. 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) { + let rows: Vec<(&str, &str)> = + entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT).map(|(_, src, tr)| (src.as_str(), tr.as_str())).collect(); + for &(src, tr) in &rows { bad.extend(crate::palette::words::row_problems(src, tr).into_iter().map(|p| format!("{}: {p}", l.code))); } + bad.extend(crate::palette::words::shared_row_words(&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..4ef6248c6a 100644 --- a/crates/ui-egui/src/palette/words.rs +++ b/crates/ui-egui/src/palette/words.rs @@ -91,6 +91,29 @@ pub(crate) fn row_problems(source: &str, text: &str) -> Vec { problems } +/// The words that more than one of a catalog's `search` rows, given as `(source, text)`, add, each +/// with the first two rows that add it. +#[cfg(test)] +pub(crate) fn shared_row_words(rows: &[(&str, &str)]) -> Vec { + let mut first: std::collections::HashMap = std::collections::HashMap::new(); + let mut problems = vec![]; + for &(source, text) in rows { + for (w, single) in row_words(text) { + if !single { + continue; + } + match first.get(&w) { + Some(&other) if other != source => problems.push(format!("{w:?} is a word of {other:?} and {source:?}")), + Some(_) => {} + None => { + first.insert(w, source); + } + } + } + } + problems +} + #[cfg(test)] mod tests { use super::*; @@ -122,4 +145,14 @@ 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 word that two `search` rows of one catalog add is reported; a word repeated in one row is not. + #[test] + fn a_word_in_two_rows_of_a_catalog_is_reported() { + let remove = "remove, delete, erase, clear"; + let image = "image, picture, photo, img, bitmap"; + assert!(shared_row_words(&[(remove, "entfernen, löschen"), (image, "bild, foto")]).is_empty()); + assert!(shared_row_words(&[(remove, "entfernen, Entfernen")]).is_empty(), "one row"); + assert_eq!(shared_row_words(&[(remove, "entfernen, löschen"), (image, "Bild, Löschen")]).len(), 1); + } }