Toggle focus between query editor and results on cmd-shift-F

This commit is contained in:
Nathan Sobo 2022-02-25 05:04:45 -07:00
parent 2147db9b41
commit 51c645f6b4

View File

@ -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<Self>) {
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<ProjectFind>, cx: &mut ViewContext<Self>) {
let theme = &self.settings.borrow().theme.find;
self.results_editor.update(cx, |editor, cx| {