From 1583dd2d6f3cfe994dbf001246d92fcb1043ec67 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Thu, 10 Jul 2025 17:15:29 +0200 Subject: [PATCH] settings_ui: Ensure context menu is properly populated (#34213) This change fixes a small issue where the right-click context menu would not be populdated on the first right click in the keymap editor and the selection of the corresponding entry would be slightly delayed. Release Notes: - N/A --- crates/settings_ui/src/keybindings.rs | 33 +++++++++++---------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/crates/settings_ui/src/keybindings.rs b/crates/settings_ui/src/keybindings.rs index 0e9b6307ae..704c45a8a6 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, + item_idx: usize, window: &mut Window, cx: &mut App, ) -> Entity { 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; };