From 1ddae2adfd43de7f8ac12531f26401b1d078be4e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 27 Feb 2022 16:15:06 -0700 Subject: [PATCH] Focus the project find results editor on a tab in the query editor --- crates/search/src/project_search.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index b823d0fd2e..be2ac6a51a 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -45,8 +45,9 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(ProjectSearchView::search); cx.add_action(ProjectSearchView::search_in_new); cx.add_action(ProjectSearchView::toggle_search_option); - cx.add_action(ProjectSearchView::toggle_focus); cx.add_action(ProjectSearchView::select_match); + cx.add_action(ProjectSearchView::toggle_focus); + cx.capture_action(ProjectSearchView::tab); } struct ProjectSearch { @@ -521,6 +522,16 @@ impl ProjectSearchView { } } + fn tab(&mut self, _: &editor::Tab, cx: &mut ViewContext) { + if self.query_editor.is_focused(cx) { + if !self.model.read(cx).match_ranges.is_empty() { + self.focus_results_editor(cx); + } + } else { + cx.propagate_action() + } + } + fn focus_results_editor(&self, cx: &mut ViewContext) { self.query_editor.update(cx, |query_editor, cx| { let cursor = query_editor.newest_anchor_selection().head();