From 9dc608dc4b4dedd11638d7cb472456e77d9272b6 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 9 Mar 2023 19:32:09 -0800 Subject: [PATCH] Switch from changing the meaning of the predicate to adding an additional match_dispatch_path_context API for UI elements --- crates/gpui/src/app.rs | 4 ++-- crates/gpui/src/keymap_matcher/binding.rs | 9 +++++++++ crates/gpui/src/keymap_matcher/keymap_context.rs | 8 +------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 31563010b723d88b4f834084fba91cb3ecd9a15c..ab88a39a9aac7e4a705bfc7f4df2c668d08b6f83 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1248,7 +1248,7 @@ impl MutableAppContext { self.keystroke_matcher .bindings_for_action_type(action.as_any().type_id()) .find_map(|b| { - if b.match_context(&contexts) { + if b.match_dispatch_path_context(&contexts) { Some(b.keystrokes().into()) } else { None @@ -1283,7 +1283,7 @@ impl MutableAppContext { deserialize("{}").ok()?, self.keystroke_matcher .bindings_for_action_type(*type_id) - .filter(|b| b.match_context(&contexts)) + .filter(|b| b.match_dispatch_path_context(&contexts)) .collect(), )) } else { diff --git a/crates/gpui/src/keymap_matcher/binding.rs b/crates/gpui/src/keymap_matcher/binding.rs index c1cfd14e82d8d3e3235a7a2c3e7d507cd78d9648..1b0217b5ff141751a8b2a35ffa37e93774f67c93 100644 --- a/crates/gpui/src/keymap_matcher/binding.rs +++ b/crates/gpui/src/keymap_matcher/binding.rs @@ -42,6 +42,15 @@ impl Binding { .unwrap_or(true) } + pub fn match_dispatch_path_context(&self, contexts: &[KeymapContext]) -> bool { + for i in 0..contexts.len() { + if self.match_context(&contexts[i..]) { + return true; + } + } + false + } + pub fn match_keys_and_context( &self, pending_keystrokes: &Vec, diff --git a/crates/gpui/src/keymap_matcher/keymap_context.rs b/crates/gpui/src/keymap_matcher/keymap_context.rs index fbaaa5fbc5d1cb9f7f111fbdeb83a8447ee6992b..bbf6bfc14bad820cd95c1525c5b673f8b8c04dcc 100644 --- a/crates/gpui/src/keymap_matcher/keymap_context.rs +++ b/crates/gpui/src/keymap_matcher/keymap_context.rs @@ -64,13 +64,7 @@ impl KeymapContextPredicate { pub fn eval(&self, contexts: &[KeymapContext]) -> bool { let Some(context) = contexts.first() else { return false }; match self { - Self::Identifier(name) => { - if (&context.set).contains(name.as_str()) { - true - } else { - self.eval(&contexts[1..]) - } - } + Self::Identifier(name) => (&context.set).contains(name.as_str()), Self::Equal(left, right) => context .map .get(left.as_str())