From 625b29d243c4e163d39c7be5276ebaca0604e3a2 Mon Sep 17 00:00:00 2001 From: ian <141902143+yumosx@users.noreply.github.com> Date: Thu, 16 Jul 2026 19:07:07 +0800 Subject: [PATCH] Fix focus handling in ProjectSearchBar. (#61093) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Fix #61023 When project search is already open and focused, pressing the project search shortcut again (`cmd-shift-f` / `ctrl-shift-f`) only re-focused the query editor and did not select the existing query text. That made it hard to quickly retype a search term—especially after a no-results search, when focus stays in the search bar. This aligns project search behavior with buffer search, where `FocusSearch` focuses and selects the query. ## Solution In `ProjectSearchBar::focus_search`, call `focus_query_editor` instead of only focusing the query editor. `focus_query_editor` already focuses the field and selects all text (same path used by `DeploySearch`). ## Testing - [ ] Manual: open project search → type a non-matching query → Enter → press project search shortcut again → query text should be selected so typing replaces it - [ ] Manual: same flow after a search that returns matches - [ ] Manual: compare with buffer search (`cmd-f` / `ctrl-f`) to confirm consistent “refocus selects query” behavior - Platforms: tested / to be tested on macOS; Linux/Windows should behave the same via the shared `FocusSearch` action No automated test added yet; a `gpui::test` that deploys project search, dispatches `FocusSearch`, and asserts the query editor selection would be a good follow-up. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - N/A --- crates/search/src/project_search.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index d451190c9f..375f6b7dfa 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1981,7 +1981,7 @@ impl ProjectSearchBar { fn focus_search(&mut self, window: &mut Window, cx: &mut Context) { if let Some(search_view) = self.active_project_search.as_ref() { search_view.update(cx, |search_view, cx| { - search_view.query_editor.focus_handle(cx).focus(window, cx); + search_view.focus_query_editor(window, cx); }); } }