This commit is contained in:
Junkui Zhang 2025-08-26 00:21:22 +08:00
parent 11bc6586d8
commit b27e1ec5c7
2 changed files with 9 additions and 35 deletions

View file

@ -1,7 +1,5 @@
use std::rc::Rc; use std::rc::Rc;
use collections::HashMap;
use crate::{ use crate::{
Action, AsKeystroke, DummyKeyboardMapper, InvalidKeystrokeError, KeyBindingContextPredicate, Action, AsKeystroke, DummyKeyboardMapper, InvalidKeystrokeError, KeyBindingContextPredicate,
KeybindingKeystroke, Keystroke, PlatformKeyboardMapper, SharedString, KeybindingKeystroke, Keystroke, PlatformKeyboardMapper, SharedString,
@ -41,7 +39,6 @@ impl KeyBinding {
context_predicate, context_predicate,
false, false,
None, None,
None,
&DummyKeyboardMapper, &DummyKeyboardMapper,
) )
.unwrap() .unwrap()
@ -53,31 +50,20 @@ impl KeyBinding {
action: Box<dyn Action>, action: Box<dyn Action>,
context_predicate: Option<Rc<KeyBindingContextPredicate>>, context_predicate: Option<Rc<KeyBindingContextPredicate>>,
use_key_equivalents: bool, use_key_equivalents: bool,
key_equivalents: Option<&HashMap<char, char>>,
action_input: Option<SharedString>, action_input: Option<SharedString>,
keyboard_mapper: &dyn PlatformKeyboardMapper, keyboard_mapper: &dyn PlatformKeyboardMapper,
) -> std::result::Result<Self, InvalidKeystrokeError> { ) -> std::result::Result<Self, InvalidKeystrokeError> {
let mut keystrokes: SmallVec<[Keystroke; 2]> = keystrokes let keystrokes: SmallVec<[KeybindingKeystroke; 2]> = keystrokes
.split_whitespace() .split_whitespace()
.map(Keystroke::parse) .map(|source| {
.collect::<std::result::Result<_, _>>()?; let keystroke = Keystroke::parse(source)?;
Ok(KeybindingKeystroke::new(
if let Some(equivalents) = key_equivalents { keystroke,
for keystroke in keystrokes.iter_mut() { use_key_equivalents,
if keystroke.key.chars().count() == 1 keyboard_mapper,
&& let Some(key) = equivalents.get(&keystroke.key.chars().next().unwrap()) ))
{
keystroke.key = key.to_string();
}
}
}
let keystrokes = keystrokes
.into_iter()
.map(|keystroke| {
KeybindingKeystroke::new(keystroke, use_key_equivalents, keyboard_mapper)
}) })
.collect(); .collect::<std::result::Result<_, _>>()?;
Ok(Self { Ok(Self {
keystrokes, keystrokes,

View file

@ -212,9 +212,6 @@ impl KeymapFile {
} }
pub fn load(content: &str, cx: &App) -> KeymapFileLoadResult { pub fn load(content: &str, cx: &App) -> KeymapFileLoadResult {
let key_equivalents =
crate::key_equivalents::get_key_equivalents(cx.keyboard_layout().id());
if content.is_empty() { if content.is_empty() {
return KeymapFileLoadResult::Success { return KeymapFileLoadResult::Success {
key_bindings: Vec::new(), key_bindings: Vec::new(),
@ -256,12 +253,6 @@ impl KeymapFile {
} }
}; };
let key_equivalents = if *use_key_equivalents {
key_equivalents.as_ref()
} else {
None
};
let mut section_errors = String::new(); let mut section_errors = String::new();
if !unrecognized_fields.is_empty() { if !unrecognized_fields.is_empty() {
@ -280,7 +271,6 @@ impl KeymapFile {
action, action,
context_predicate.clone(), context_predicate.clone(),
*use_key_equivalents, *use_key_equivalents,
key_equivalents,
cx, cx,
); );
match result { match result {
@ -339,7 +329,6 @@ impl KeymapFile {
action: &KeymapAction, action: &KeymapAction,
context: Option<Rc<KeyBindingContextPredicate>>, context: Option<Rc<KeyBindingContextPredicate>>,
use_key_equivalents: bool, use_key_equivalents: bool,
key_equivalents: Option<&HashMap<char, char>>,
cx: &App, cx: &App,
) -> std::result::Result<KeyBinding, String> { ) -> std::result::Result<KeyBinding, String> {
let (build_result, action_input_string) = match &action.0 { let (build_result, action_input_string) = match &action.0 {
@ -408,7 +397,6 @@ impl KeymapFile {
action, action,
context, context,
use_key_equivalents, use_key_equivalents,
key_equivalents,
action_input_string.map(SharedString::from), action_input_string.map(SharedString::from),
cx.keyboard_mapper(), cx.keyboard_mapper(),
) { ) {