From 51c645f6b4037b9b53a5600ac7cd93d54f7bb679 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 25 Feb 2022 05:04:45 -0700 Subject: [PATCH] Toggle focus between query editor and results on cmd-shift-F --- crates/find/src/project_find.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/find/src/project_find.rs b/crates/find/src/project_find.rs index 0743e2cce0af45d4e8327daab3ddeb3f722f7ae1..ff34015d95b8142339e7aed67769f5483689ad74 100644 --- a/crates/find/src/project_find.rs +++ b/crates/find/src/project_find.rs @@ -13,15 +13,18 @@ use crate::SearchOption; action!(Deploy); action!(Search); action!(ToggleSearchOption, SearchOption); +action!(ToggleFocus); pub fn init(cx: &mut MutableAppContext) { cx.add_bindings([ - Binding::new("cmd-shift-F", Deploy, None), + Binding::new("cmd-shift-F", ToggleFocus, Some("ProjectFindView")), + Binding::new("cmd-shift-F", Deploy, Some("Workspace")), Binding::new("enter", Search, Some("ProjectFindView")), ]); cx.add_action(ProjectFindView::deploy); cx.add_action(ProjectFindView::search); cx.add_action(ProjectFindView::toggle_search_option); + cx.add_action(ProjectFindView::toggle_focus); } struct ProjectFind { @@ -253,6 +256,14 @@ impl ProjectFindView { cx.notify(); } + fn toggle_focus(&mut self, _: &ToggleFocus, cx: &mut ViewContext) { + if self.query_editor.is_focused(cx) { + cx.focus(&self.results_editor); + } else { + cx.focus(&self.query_editor); + } + } + fn on_model_changed(&mut self, _: ModelHandle, cx: &mut ViewContext) { let theme = &self.settings.borrow().theme.find; self.results_editor.update(cx, |editor, cx| {