From 7314838fa469f62489030e8eb0b381abc4ad768d Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:49:23 +0100 Subject: [PATCH] project search: Move to results with ESC --- crates/search2/src/project_search.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/search2/src/project_search.rs b/crates/search2/src/project_search.rs index ab94466cf7..8c673edbe4 100644 --- a/crates/search2/src/project_search.rs +++ b/crates/search2/src/project_search.rs @@ -1224,6 +1224,14 @@ impl ProjectSearchView { cx.theme().colors().border } } + fn move_focus_to_results(&mut self, cx: &mut ViewContext) { + if !self.results_editor.focus_handle(cx).is_focused(cx) + && !self.model.read(cx).match_ranges.is_empty() + { + cx.stop_propagation(); + return self.focus_results_editor(cx); + } + } } impl Default for ProjectSearchBar { @@ -1398,6 +1406,15 @@ impl ProjectSearchBar { } } + fn move_focus_to_results(&self, cx: &mut ViewContext) { + if let Some(search_view) = self.active_project_search.as_ref() { + search_view.update(cx, |search_view, cx| { + search_view.move_focus_to_results(cx); + }); + cx.notify(); + } + } + fn activate_search_mode(&self, mode: SearchMode, cx: &mut ViewContext) { // Update Current Mode if let Some(search_view) = self.active_project_search.as_ref() { @@ -1754,6 +1771,7 @@ impl Render for ProjectSearchBar { .key_context(key_context) .flex_grow() .gap_2() + .on_action(cx.listener(|this, _: &ToggleFocus, cx| this.move_focus_to_results(cx))) .on_action(cx.listener(|this, _: &ToggleFilters, cx| { this.toggle_filters(cx); }))