From 027fe1b4b5ea02d9b329299b2cbabbd5240c0370 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Fri, 31 Jan 2025 13:03:11 -0600 Subject: [PATCH] Ensure pane where search buttons are clicked is focused before dispatching action (#24037) Closes #23906 Note: Changes the focused pane when search UI is interacted with on an unfocused pane rather than leaving the focused pane unchanged as focusing on click is more likely to be the expected behavior Release Notes: - Fixes an issue with search actions so that they now execute on the clicked pane rather than the focused pane when using search UI in multiple panes --- crates/search/src/search_bar.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/search/src/search_bar.rs b/crates/search/src/search_bar.rs index 897c4c2c2bf2b4d7c7fed9ad8f5bacc9a5ad1dde..84fc534c2f6c77e4e46f61bdcfe83d71803d72b3 100644 --- a/crates/search/src/search_bar.rs +++ b/crates/search/src/search_bar.rs @@ -14,7 +14,15 @@ pub(super) fn render_nav_button( icon, ) .shape(IconButtonShape::Square) - .on_click(|_, window, cx| window.dispatch_action(action.boxed_clone(), cx)) + .on_click({ + let focus_handle = focus_handle.clone(); + move |_, window, cx| { + if !focus_handle.is_focused(&window) { + window.focus(&focus_handle); + } + window.dispatch_action(action.boxed_clone(), cx) + } + }) .tooltip(move |window, cx| Tooltip::for_action_in(tooltip, action, &focus_handle, window, cx)) .disabled(!active) }