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

This commit is contained in:
Nathan Sobo 2022-02-27 16:15:06 -07:00
parent 71241b1fb8
commit 1ddae2adfd

View File

@ -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();