command mode exit coded from hardcoded system

This commit is contained in:
filipriec
2025-02-28 14:44:47 +01:00
parent 3aff4654ec
commit 0af38b6bd5
3 changed files with 27 additions and 2 deletions

View File

@@ -176,6 +176,22 @@ impl Config {
}
}
pub fn is_enter_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
if let Some(bindings) = self.keybindings.get("enter_command_mode") {
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
} else {
false
}
}
pub fn is_exit_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
if let Some(bindings) = self.keybindings.get("exit_command_mode") {
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
} else {
false
}
}
pub fn has_key_for_action(&self, action: &str, key_char: char) -> bool {
if let Some(bindings) = self.keybindings.get(action) {
for binding in bindings {

View File

@@ -83,6 +83,14 @@ impl EventHandler {
current_position: &mut u64,
total_count: u64,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
// Check for exit_command_mode binding first
if config.is_exit_command_mode(key.code, key.modifiers) {
self.command_mode = false;
self.command_input.clear();
return Ok((false, String::new()));
}
// Existing command mode handling
let (should_exit, message, exit_command_mode) = command_mode::handle_command_event(
key,
config,
@@ -114,7 +122,7 @@ impl EventHandler {
form_state: &mut FormState,
) -> Result<bool, Box<dyn std::error::Error>> {
// Enter command mode
if !self.is_edit_mode && key.code == KeyCode::Char(':') {
if !self.is_edit_mode && config.is_enter_command_mode(key.code, key.modifiers) {
self.command_mode = true;
self.command_input.clear();
self.command_message.clear();