Add cmd-g and cmd-shift-g to jump to next / previous result

Nathan Sobo created

I added the action handler on Pane so we can use these bindings when the find bar isn't focused.

Change summary

crates/find/src/find.rs      | 11 ++++++++++-
crates/workspace/src/pane.rs |  6 ++++++
2 files changed, 16 insertions(+), 1 deletion(-)

Detailed changes

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<Pane>) {
+        if let Some(find_bar) = pane.toolbar::<FindBar>() {
+            find_bar.update(cx, |find_bar, cx| find_bar.go_to_match(action, cx));
+        }
+    }
+
     fn on_query_editor_event(
         &mut self,
         _: ViewHandle<Editor>,

crates/workspace/src/pane.rs 🔗

@@ -417,6 +417,12 @@ impl Pane {
         cx.notify();
     }
 
+    pub fn toolbar<T: Toolbar>(&self) -> Option<ViewHandle<T>> {
+        self.toolbars
+            .get(&TypeId::of::<T>())
+            .and_then(|toolbar| toolbar.to_any().downcast())
+    }
+
     pub fn active_toolbar(&self) -> Option<AnyViewHandle> {
         let type_id = self.active_toolbar_type?;
         let toolbar = self.toolbars.get(&type_id)?;