Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
keymap: Allow upper-case keys in keybinds (#27813)
Ben Kunklea1bef28da322
diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rsindex 2a2712bf305..109f76a5e0d 100644--- a/crates/editor/src/test/editor_test_context.rs+++ b/crates/editor/src/test/editor_test_context.rs@@ -240,7 +240,7 @@ impl EditorTestContext {// unlike cx.simulate_keystrokes(), this does not run_until_parked// so you can use it to test detailed timingpub fn simulate_keystroke(&mut self, keystroke_text: &str) {- let keystroke = Keystroke::parse_case_insensitive(keystroke_text).unwrap();+ let keystroke = Keystroke::parse(keystroke_text).unwrap();self.cx.dispatch_keystroke(self.window, keystroke);}diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rsindex e639da7654f..be36324c0f7 100644--- a/crates/gpui/src/app/test_context.rs+++ b/crates/gpui/src/app/test_context.rs@@ -399,7 +399,7 @@ impl TestAppContext {pub fn simulate_keystrokes(&mut self, window: AnyWindowHandle, keystrokes: &str) {for keystroke in keystrokes.split(' ')- .map(Keystroke::parse_case_insensitive)+ .map(Keystroke::parse).map(Result::unwrap){self.dispatch_keystroke(window, keystroke);@@ -413,11 +413,7 @@ impl TestAppContext {/// will type abc into your current editor/// This will also run the background executor until it's parked.pub fn simulate_input(&mut self, window: AnyWindowHandle, input: &str) {- for keystroke in input- .split("")- .map(Keystroke::parse_case_insensitive)- .map(Result::unwrap)- {+ for keystroke in input.split("").map(Keystroke::parse).map(Result::unwrap) {self.dispatch_keystroke(window, keystroke);}diff --git a/crates/gpui/src/platform/keystroke.rs b/crates/gpui/src/platform/keystroke.rsindex 67c8b64c144..e2e977539fa 100644--- a/crates/gpui/src/platform/keystroke.rs+++ b/crates/gpui/src/platform/keystroke.rs@@ -42,9 +42,9 @@ impl Display for InvalidKeystrokeError {}/// Sentence explaining what keystroke parser expects, starting with "Expected ..."-pub const KEYSTROKE_PARSE_EXPECTED_MESSAGE: &str = "Expected a sequence of lowercase modifiers \+pub const KEYSTROKE_PARSE_EXPECTED_MESSAGE: &str = "Expected a sequence of modifiers \(`ctrl`, `alt`, `shift`, `fn`, `cmd`, `super`, or `win`) \- followed by a lowercase key, separated by `-`.";+ followed by a key, separated by `-`.";impl Keystroke {/// When matching a key we cannot know whether the user intended to type@@ -81,28 +81,6 @@ impl Keystroke {/// secondary means "cmd" on macOS and "ctrl" on other platforms/// when matching a key with an key_char set will be matched without it.pub fn parse(source: &str) -> std::result::Result<Self, InvalidKeystrokeError> {- return Self::parse_impl(source, true);- }-- /// Parse a keystroke case-insensitively. This means- /// keystrokes like `ctrl-T` will not be rejected.- /// Useful in tests to allow more concise keystroke inputs,- /// e.g., `simulate_keystrokes("ctrl-T")` instead of `simulate_keystrokes("ctrl-shift-t")`.- /// This also allows `simulate_input` style functions to support capital letters,- /// e.g., `simulate_input("Title Case")` can work by just parsing each character as a keystroke- /// and dispatching it, instead of needing to parse something like- /// `simulate_input("shift-title shift-case")`.- #[cfg(any(test, feature = "test-support"))]- pub fn parse_case_insensitive(- source: &str,- ) -> std::result::Result<Self, InvalidKeystrokeError> {- return Self::parse_impl(source, false);- }-- fn parse_impl(- source: &str,- case_sensitive: bool,- ) -> std::result::Result<Self, InvalidKeystrokeError> {let mut control = false;let mut alt = false;let mut shift = false;@@ -166,16 +144,10 @@ impl Keystroke {}if component.len() == 1 && component.as_bytes()[0].is_ascii_uppercase() {- if case_sensitive {- return Err(InvalidKeystrokeError {- keystroke: source.to_owned(),- });- } else {- // Convert to shift + lowercase char if parsing case insensitively- shift = true;- key_str.make_ascii_lowercase();- }- } else if case_sensitive {+ // Convert to shift + lowercase char+ shift = true;+ key_str.make_ascii_lowercase();+ } else {// convert ascii chars to lowercase so that named keys like "tab" and "enter"// are accepted case insensitively and stored how we expect so they are matched properlykey_str.make_ascii_lowercase()diff --git a/crates/terminal/src/mappings/keys.rs b/crates/terminal/src/mappings/keys.rsindex ef1b3464af1..785cfaeacce 100644--- a/crates/terminal/src/mappings/keys.rs+++ b/crates/terminal/src/mappings/keys.rs@@ -398,7 +398,7 @@ mod test {false),to_esc_str(- &Keystroke::parse_case_insensitive(&format!("ctrl-{}", upper)).unwrap(),+ &Keystroke::parse(&format!("ctrl-{}", upper)).unwrap(),&mode,false),@@ -415,7 +415,7 @@ mod test {for character in ascii_printable {assert_eq!(to_esc_str(- &Keystroke::parse_case_insensitive(&format!("alt-{}", character)).unwrap(),+ &Keystroke::parse(&format!("alt-{}", character)).unwrap(),&TermMode::NONE,true)