Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
settings_ui: Ensure context menu is properly populated (#34213)
Finn Evers1583dd2d6f3c
diff --git a/crates/settings_ui/src/keybindings.rs b/crates/settings_ui/src/keybindings.rsindex 0e9b6307ae1..704c45a8a64 100644--- a/crates/settings_ui/src/keybindings.rs+++ b/crates/settings_ui/src/keybindings.rs@@ -814,24 +814,12 @@ impl Render for KeymapEditor {});right_click_menu(("keymap-table-row-menu", row_index))- .trigger({- let this = cx.weak_entity();- move |is_menu_open: bool, _window, cx| {- if is_menu_open {- this.update(cx, |this, cx| {- if this.selected_index != Some(row_index) {- this.selected_index = Some(row_index);- cx.notify();- }- })- .ok();- }- row- }- })+ .trigger(move |_, _, _| row).menu({let this = cx.weak_entity();- move |window, cx| build_keybind_context_menu(&this, window, cx)+ move |window, cx| {+ build_keybind_context_menu(&this, row_index, window, cx)+ }}).into_any_element()}),@@ -1503,14 +1491,19 @@ impl Render for KeystrokeInput {fn build_keybind_context_menu(this: &WeakEntity<KeymapEditor>,+ item_idx: usize,window: &mut Window,cx: &mut App,) -> Entity<ContextMenu> {ContextMenu::build(window, cx, |menu, _window, cx| {- let Some(this) = this.upgrade() else {- return menu;- };- let selected_binding = this.read_with(cx, |this, _cx| this.selected_binding().cloned());+ let selected_binding = this+ .update(cx, |this, _cx| {+ this.selected_index = Some(item_idx);+ this.selected_binding().cloned()+ })+ .ok()+ .flatten();+let Some(selected_binding) = selected_binding else {return menu;};