multiletter shortcuts are now implemented where first letter is a waiting command
This commit is contained in:
@@ -21,7 +21,7 @@ move_word_end_prev = ["ge"] # Move to end of previous word
|
||||
move_line_start = ["0"] # Move to beginning of line
|
||||
move_line_end = ["$"] # Move to end of line
|
||||
move_first_line = ["gg"] # Move to first line of form
|
||||
move_last_line = ["G"] # Move to last line of form
|
||||
move_last_line = ["x"] # Move to last line of form
|
||||
|
||||
[colors]
|
||||
theme = "dark"
|
||||
|
||||
@@ -233,6 +233,7 @@ impl EventHandler {
|
||||
if key.modifiers.is_empty() {
|
||||
self.key_sequence_tracker.add_key(key.code);
|
||||
let sequence = self.key_sequence_tracker.get_sequence();
|
||||
let sequence_str = self.key_sequence_tracker.sequence_to_string();
|
||||
|
||||
// First check for multi-key sequences
|
||||
if let Some(action) = config.matches_key_sequence(&sequence) {
|
||||
@@ -241,11 +242,17 @@ impl EventHandler {
|
||||
return Ok((false, result));
|
||||
}
|
||||
|
||||
// If single key, check for single key actions
|
||||
// Only execute single-key actions if this key doesn't begin any multi-key sequence
|
||||
// This prevents "g" from triggering an action when it could be the start of "gg" or "ge"
|
||||
if sequence.len() == 1 {
|
||||
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
||||
let result = self.execute_action(action, form_state)?;
|
||||
return Ok((false, result));
|
||||
let is_prefix_of_multikey = self.is_prefix_of_multikey_binding(&sequence_str, config);
|
||||
|
||||
if !is_prefix_of_multikey {
|
||||
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
||||
let result = self.execute_action(action, form_state)?;
|
||||
self.key_sequence_tracker.reset(); // Reset after executing
|
||||
return Ok((false, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -278,6 +285,24 @@ impl EventHandler {
|
||||
Ok((false, self.command_message.clone()))
|
||||
}
|
||||
|
||||
// Add this helper method to check if a key sequence is a prefix of any multi-key binding
|
||||
fn is_prefix_of_multikey_binding(&self, sequence: &str, config: &Config) -> bool {
|
||||
for (_, bindings) in &config.keybindings {
|
||||
for binding in bindings {
|
||||
// Skip bindings with modifiers (those contain '+')
|
||||
if binding.contains('+') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if binding starts with our sequence and is longer
|
||||
if binding.len() > sequence.len() && binding.starts_with(sequence) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn execute_action(
|
||||
&mut self,
|
||||
action: &str,
|
||||
|
||||
Reference in New Issue
Block a user