diff --git a/crates/ui-egui/src/prefs_search.rs b/crates/ui-egui/src/prefs_search.rs index 198c99212..ad909d91a 100644 --- a/crates/ui-egui/src/prefs_search.rs +++ b/crates/ui-egui/src/prefs_search.rs @@ -698,14 +698,17 @@ fn strip_mark(c: char) -> char { fn english_hit(query: &str, shown: &str) -> bool { use std::cell::RefCell; + type Map = HashMap>; thread_local! { - static MAP: RefCell<(String, HashMap>)> = RefCell::new((String::new(), HashMap::new())); + // (language, shown text -> English sources, English text -> shown text in the language) + static MAP: RefCell<(String, Map, Map)> = RefCell::new((String::new(), Map::new(), Map::new())); } MAP.with(|slot| { let lang = crate::i18n::language().to_string(); let mut slot = slot.borrow_mut(); if slot.0 != lang { - let mut map: HashMap> = HashMap::new(); + let mut map = Map::new(); + let mut translated = Map::new(); let locale = crate::i18n::Locale::for_language(&lang); crate::i18n::each_english_message(|id, english| { if english.contains('{') { @@ -714,12 +717,21 @@ fn english_hit(query: &str, shown: &str) -> bool { let shown = locale.text(id); if shown != english { map.entry(shown.to_string()).or_default().push(english.to_string()); + translated.entry(english.to_lowercase()).or_default().push(shown.to_string()); } }); - *slot = (lang, map); + *slot = (lang, map, translated); } + let translated = &slot.2; slot.1.get(shown).is_some_and(|lines| { - lines.iter().any(|english| setting_score(query, english) > 0 || keywords(english).iter().any(|word| setting_score(query, word) > 0)) + lines.iter().any(|english| { + setting_score(query, english) > 0 + || keywords(english).iter().any(|word| { + setting_score(query, word) > 0 + // The old label of a renamed setting, as the language wrote it. + || translated.get(&word.to_lowercase()).is_some_and(|legacy| legacy.iter().any(|text| setting_score(query, text) > 0)) + }) + }) }) }) } @@ -997,6 +1009,15 @@ mod tests { assert!(matches_text("مجلدات", &[label]), "one word still matches"); } + /// A renamed setting is still found by its old label in the user's language, not only in English. + #[test] + fn search_finds_a_renamed_setting_by_its_old_localized_label() { + let _language = crate::i18n::scope("de"); + let label = crate::i18n::tr("prefs.sketch.state_icons"); + assert!(matches_text("Skizzensymbole", &[label]), "{label} is the former Skizzensymbole in der Farbe ihres Zustands"); + assert!(!matches_text("Qqqq", &[label])); + } + /// The search field and its empty result name the window they search (#8318): "Search /// settings" under a "Preferences" title read as two names for one window. #[test]