From b1639e56772cc48f1d9fe90a382b63956b06e171 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 30 Jan 2022 20:59:20 -0700 Subject: [PATCH] Add cmd-g and cmd-shift-g to jump to next / previous result I added the action handler on Pane so we can use these bindings when the find bar isn't focused. --- crates/find/src/find.rs | 11 ++++++++++- crates/workspace/src/pane.rs | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/find/src/find.rs b/crates/find/src/find.rs index 65a164b96996013a230cbb0cf8eda078db54be8c..f7e82f4c02fc5bc6e471b99928078cb29483c4ae 100644 --- a/crates/find/src/find.rs +++ b/crates/find/src/find.rs @@ -17,7 +17,7 @@ use std::{ ops::Range, sync::Arc, }; -use workspace::{ItemViewHandle, Settings, Toolbar, Workspace}; +use workspace::{ItemViewHandle, Pane, Settings, Toolbar, Workspace}; action!(Deploy, bool); action!(Cancel); @@ -46,12 +46,15 @@ pub fn init(cx: &mut MutableAppContext) { Binding::new("cmd-f", FocusEditor, Some("FindBar")), Binding::new("enter", GoToMatch(Direction::Next), Some("FindBar")), Binding::new("shift-enter", GoToMatch(Direction::Prev), Some("FindBar")), + Binding::new("cmd-g", GoToMatch(Direction::Next), Some("Pane")), + Binding::new("cmd-shift-G", GoToMatch(Direction::Prev), Some("Pane")), ]); cx.add_action(FindBar::deploy); cx.add_action(FindBar::cancel); cx.add_action(FindBar::focus_editor); cx.add_action(FindBar::toggle_mode); cx.add_action(FindBar::go_to_match); + cx.add_action(FindBar::go_to_match_on_pane); } struct FindBar { @@ -386,6 +389,12 @@ impl FindBar { } } + fn go_to_match_on_pane(pane: &mut Pane, action: &GoToMatch, cx: &mut ViewContext) { + if let Some(find_bar) = pane.toolbar::() { + find_bar.update(cx, |find_bar, cx| find_bar.go_to_match(action, cx)); + } + } + fn on_query_editor_event( &mut self, _: ViewHandle, diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index a112213795951cae3607cbb8a72d4d0c487ba892..6721401817d3bdd38ff22da4d71bfdd2dc297361 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -417,6 +417,12 @@ impl Pane { cx.notify(); } + pub fn toolbar(&self) -> Option> { + self.toolbars + .get(&TypeId::of::()) + .and_then(|toolbar| toolbar.to_any().downcast()) + } + pub fn active_toolbar(&self) -> Option { let type_id = self.active_toolbar_type?; let toolbar = self.toolbars.get(&type_id)?;