Focus the project find results editor on a tab in the query editor

Nathan Sobo created

Change summary

crates/search/src/project_search.rs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

Detailed changes

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<Self>) {
+        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>) {
         self.query_editor.update(cx, |query_editor, cx| {
             let cursor = query_editor.newest_anchor_selection().head();