From 01488c4f915e1680f7cac183d836bd557b190245 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 13 May 2025 10:36:18 +0200 Subject: [PATCH] Fix project search focus not toggling between query and results on ESC (#30613) Before: https://github.com/user-attachments/assets/dc5b7ab3-b9bc-4aa3-9f0c-1694c41ec7e7 After: https://github.com/user-attachments/assets/8087004e-c1fd-4390-9f79-b667e8ba874b Release Notes: - Fixed project search focus not toggling between query and results on ESC --- crates/search/src/project_search.rs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 8485d8e791..0d49cf3955 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -106,6 +106,40 @@ pub fn init(cx: &mut App) { ProjectSearchView::search_in_new(workspace, action, window, cx) }); + register_workspace_action_for_present_search( + workspace, + |workspace, _: &menu::Cancel, window, cx| { + if let Some(project_search_bar) = workspace + .active_pane() + .read(cx) + .toolbar() + .read(cx) + .item_of_type::() + { + project_search_bar.update(cx, |project_search_bar, cx| { + let search_is_focused = project_search_bar + .active_project_search + .as_ref() + .is_some_and(|search_view| { + search_view + .read(cx) + .query_editor + .read(cx) + .focus_handle(cx) + .is_focused(window) + }); + if search_is_focused { + project_search_bar.move_focus_to_results(window, cx); + } else { + project_search_bar.focus_search(window, cx) + } + }); + } else { + cx.propagate(); + } + }, + ); + // Both on present and dismissed search, we need to unconditionally handle those actions to focus from the editor. workspace.register_action(move |workspace, action: &DeploySearch, window, cx| { if workspace.has_active_modal(window, cx) {