working double shortcuts

This commit is contained in:
filipriec
2025-02-27 13:58:47 +01:00
parent 312d5fff36
commit a7c105d903
5 changed files with 345 additions and 154 deletions

View File

@@ -46,6 +46,11 @@ impl Config {
continue;
}
for binding in bindings {
// Skip multi-key bindings when checking for single key actions
if binding.len() > 1 && !binding.contains('+') {
continue;
}
if Self::matches_keybinding(binding, key, modifiers) {
return Some(action);
}
@@ -54,11 +59,52 @@ impl Config {
None
}
/// Checks if a sequence of keys matches any keybinding
pub fn matches_key_sequence(&self, sequence: &[KeyCode]) -> Option<&str> {
if sequence.is_empty() {
return None;
}
// Convert key sequence to a string (for simple character sequences)
let sequence_str: String = sequence.iter().filter_map(|key| {
if let KeyCode::Char(c) = key {
Some(*c)
} else {
None
}
}).collect();
if sequence_str.is_empty() {
return None;
}
// Check if this sequence matches any binding
for (action, bindings) in &self.keybindings {
for binding in bindings {
// Skip bindings with modifiers (those contain '+')
if binding.contains('+') {
continue;
}
if binding == &sequence_str {
return Some(action);
}
}
}
None
}
fn matches_keybinding(
binding: &str,
key: KeyCode,
modifiers: KeyModifiers,
) -> bool {
// For multi-character bindings without modifiers, we handle them in matches_key_sequence
if binding.len() > 1 && !binding.contains('+') {
return false;
}
let parts: Vec<&str> = binding.split('+').collect();
let mut expected_modifiers = KeyModifiers::empty();
let mut expected_key = None;