From 8d94de8eb2e6b6b48f9a45b4aeb7a92c7176f4b8 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Oct 2022 11:27:26 -0700 Subject: [PATCH] WIP: Change to matches to vec --- crates/editor/src/blink_manager.rs | 1 - crates/gpui/src/app.rs | 7 +++++++ crates/gpui/src/keymap.rs | 16 +++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/blink_manager.rs b/crates/editor/src/blink_manager.rs index df66ec2125..681692f0f5 100644 --- a/crates/editor/src/blink_manager.rs +++ b/crates/editor/src/blink_manager.rs @@ -71,7 +71,6 @@ impl BlinkManager { if epoch == self.blink_epoch && self.enabled && !self.blinking_paused { self.visible = !self.visible; cx.notify(); - dbg!(cx.handle()); let epoch = self.next_blink_epoch(); let interval = self.blink_interval; diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 925a4542aa..17aa758bb6 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1524,6 +1524,13 @@ impl MutableAppContext { pub fn dispatch_keystroke(&mut self, window_id: usize, keystroke: &Keystroke) -> bool { if let Some(focused_view_id) = self.focused_view_id(window_id) { + // For each view in self + // - Get it's keymap context + // - Try to execute keybinding + + // For us, get out dispatch path + // - ONLY execute for that terminal path + let dispatch_path = self .ancestors(window_id, focused_view_id) .map(|view_id| { diff --git a/crates/gpui/src/keymap.rs b/crates/gpui/src/keymap.rs index 603190a810..9218b849ec 100644 --- a/crates/gpui/src/keymap.rs +++ b/crates/gpui/src/keymap.rs @@ -77,10 +77,7 @@ where pub enum MatchResult { None, Pending, - Match { - view_id: usize, - action: Box, - }, + Match(Vec<(usize, Box)>), } impl Debug for MatchResult { @@ -157,8 +154,10 @@ impl Matcher { dispatch_path: Vec<(usize, Context)>, ) -> MatchResult { let mut any_pending = false; + let mut matched_bindings = Vec::new(); let first_keystroke = self.pending.is_empty(); + dbg!(&dispatch_path); for (view_id, context) in dispatch_path { if !first_keystroke && !self.pending.contains_key(&view_id) { continue; @@ -185,10 +184,7 @@ impl Matcher { { if binding.keystrokes.len() == pending.keystrokes.len() { self.pending.remove(&view_id); - return MatchResult::Match { - view_id, - action: binding.action.boxed_clone(), - }; + matched_bindings.push((view_id, binding.action.boxed_clone())); } else { retain_pending = true; pending.context = Some(context.clone()); @@ -203,7 +199,9 @@ impl Matcher { } } - if any_pending { + if !matched_bindings.is_empty() { + MatchResult::Match(matched_bindings) + } else if any_pending { MatchResult::Pending } else { MatchResult::None