From c91ca3634f0efb71123882cb12e7e1f117230761 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 7 Oct 2026 10:50:52 +0700 Subject: [PATCH] Palette: entries rebuild when keyboard shortcuts change The command palette caches its entries per language and plug-in set (#243), but each entry also shows its shortcut: after editing shortcuts the palette kept showing the old ones until the language changed. The cache key now includes the shortcut editor's generation. From #242. Co-authored-by: WildfootW Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/palette.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 9378828a..609d0bcd 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -42,11 +42,13 @@ struct Entry { haystack: String, } -/// The palette's entries in `lang`. They are built when the language or the installed plug-ins -/// change, not on every frame while a query is typed. +/// The palette's entries in `lang`. They are built when the language, the installed plug-ins or +/// the keyboard shortcuts (shown beside each entry) change, not on every frame while a query is +/// typed. fn entries(ctx: &egui::Context, lang: crate::i18n::Lang) -> Arc> { - type Cached = ((&'static str, u64), Arc>); - let key = (lang.code(), menus::plugin_revision()); + type Cached = ((&'static str, u64, u64), Arc>); + let shortcuts = crate::shortcut_editor::GENERATION.load(std::sync::atomic::Ordering::Relaxed); + let key = (lang.code(), menus::plugin_revision(), shortcuts); let id = egui::Id::new("palette-entries"); if let Some((k, v)) = ctx.data(|d| d.get_temp::(id)) && k == key @@ -123,6 +125,9 @@ mod tests { assert!(Arc::ptr_eq(&en, &entries(&ctx, Lang::EN)), "kept while the language stays"); let zh_entries = entries(&ctx, zh); assert!(!Arc::ptr_eq(&en, &zh_entries), "rebuilt for another language"); + // Editing a shortcut rebuilds them, so the palette shows the new one. + crate::shortcut_editor::GENERATION.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + assert!(!Arc::ptr_eq(&zh_entries, &entries(&ctx, zh)), "rebuilt after a shortcut edit"); let group = zh_entries.iter().find(|e| e.id == "object.group").unwrap(); assert!(group.shown.ends_with(crate::i18n::tr(zh, "Group")), "{}", group.shown); // A query matches the English label, the shown label or the id.