command mode exit coded from hardcoded system
This commit is contained in:
@@ -7,6 +7,7 @@ force_quit = [":q!", "ctrl+shift+q"]
|
||||
save_and_quit = [":wq", "ctrl+shift+s"]
|
||||
|
||||
enter_command_mode = [":", "shift+;"]
|
||||
exit_command_mode = ["ctrl+g", "5"]
|
||||
|
||||
# MODE SPECIFIC
|
||||
# READ ONLY MODE
|
||||
@@ -26,7 +27,7 @@ move_word_end_prev = ["ge"]
|
||||
move_line_start = ["0"]
|
||||
move_line_end = ["$"]
|
||||
move_first_line = ["gg"]
|
||||
move_last_line = ["ctrl+g"]
|
||||
move_last_line = ["x"]
|
||||
|
||||
# EDIT MODE
|
||||
exit_edit_mode = ["esc", "ctrl+e"]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user