Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Remove catch all keymap and KeyPressed action
Kay Simmons327932ba3b39
diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex d4625cbce05..5b5d8f1162f 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -65,7 +65,7 @@ impl CommandPalette {action,keystrokes: bindings.iter()- .filter_map(|binding| binding.keystrokes())+ .map(|binding| binding.keystrokes()).last().map_or(Vec::new(), |keystrokes| keystrokes.to_vec()),})diff --git a/crates/gpui/src/keymap_matcher.rs b/crates/gpui/src/keymap_matcher.rsindex c7de0352328..edcc458658e 100644--- a/crates/gpui/src/keymap_matcher.rs+++ b/crates/gpui/src/keymap_matcher.rs@@ -6,24 +6,15 @@ mod keystroke;use std::{any::TypeId, fmt::Debug};use collections::HashMap;-use serde::Deserialize;use smallvec::SmallVec;-use crate::{impl_actions, Action};+use crate::Action;pub use binding::{Binding, BindingMatchResult};pub use keymap::Keymap;pub use keymap_context::{KeymapContext, KeymapContextPredicate};pub use keystroke::Keystroke;-#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize)]-pub struct KeyPressed {- #[serde(default)]- pub keystroke: Keystroke,-}--impl_actions!(gpui, [KeyPressed]);-pub struct KeymapMatcher {pub contexts: Vec<KeymapContext>,pending_views: HashMap<usize, KeymapContext>,@@ -102,13 +93,7 @@ impl KeymapMatcher {for binding in self.keymap.bindings().iter().rev() {match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..]){- BindingMatchResult::Complete(mut action) => {- // Swap in keystroke for special KeyPressed action- if action.name() == "KeyPressed" && action.namespace() == "gpui" {- action = Box::new(KeyPressed {- keystroke: keystroke.clone(),- });- }+ BindingMatchResult::Complete(action) => {matched_bindings.push((view_id, action))}BindingMatchResult::Partial => {diff --git a/crates/gpui/src/keymap_matcher/binding.rs b/crates/gpui/src/keymap_matcher/binding.rsindex 81464378848..c1cfd14e82d 100644--- a/crates/gpui/src/keymap_matcher/binding.rs+++ b/crates/gpui/src/keymap_matcher/binding.rs@@ -7,7 +7,7 @@ use super::{KeymapContext, KeymapContextPredicate, Keystroke};pub struct Binding {action: Box<dyn Action>,- keystrokes: Option<SmallVec<[Keystroke; 2]>>,+ keystrokes: SmallVec<[Keystroke; 2]>,context_predicate: Option<KeymapContextPredicate>,}@@ -23,16 +23,10 @@ impl Binding {None};- let keystrokes = if keystrokes == "*" {- None // Catch all context- } else {- Some(- keystrokes- .split_whitespace()- .map(Keystroke::parse)- .collect::<Result<_>>()?,- )- };+ let keystrokes = keystrokes+ .split_whitespace()+ .map(Keystroke::parse)+ .collect::<Result<_>>()?;Ok(Self {keystrokes,@@ -53,20 +47,10 @@ impl Binding {pending_keystrokes: &Vec<Keystroke>,contexts: &[KeymapContext],) -> BindingMatchResult {- if self- .keystrokes- .as_ref()- .map(|keystrokes| keystrokes.starts_with(&pending_keystrokes))- .unwrap_or(true)- && self.match_context(contexts)+ if self.keystrokes.as_ref().starts_with(&pending_keystrokes) && self.match_context(contexts){// If the binding is completed, push it onto the matches list- if self- .keystrokes- .as_ref()- .map(|keystrokes| keystrokes.len() == pending_keystrokes.len())- .unwrap_or(true)- {+ if self.keystrokes.as_ref().len() == pending_keystrokes.len() {BindingMatchResult::Complete(self.action.boxed_clone())} else {BindingMatchResult::Partial@@ -82,14 +66,14 @@ impl Binding {contexts: &[KeymapContext],) -> Option<SmallVec<[Keystroke; 2]>> {if self.action.eq(action) && self.match_context(contexts) {- self.keystrokes.clone()+ Some(self.keystrokes.clone())} else {None}}- pub fn keystrokes(&self) -> Option<&[Keystroke]> {- self.keystrokes.as_deref()+ pub fn keystrokes(&self) -> &[Keystroke] {+ self.keystrokes.as_slice()}pub fn action(&self) -> &dyn Action {diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rsindex 5d132275854..3d57a7fe2ae 100644--- a/crates/gpui/src/platform/mac/platform.rs+++ b/crates/gpui/src/platform/mac/platform.rs@@ -184,7 +184,7 @@ impl MacForegroundPlatform {.map(|binding| binding.keystrokes());let item;- if let Some(keystrokes) = keystrokes.flatten() {+ if let Some(keystrokes) = keystrokes {if keystrokes.len() == 1 {let keystroke = &keystrokes[0];let mut mask = NSEventModifierFlags::empty();