Detailed changes
@@ -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()),
})
@@ -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 => {
@@ -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 {
@@ -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();