command mode entering during edit mode is now forbidden

This commit is contained in:
filipriec
2025-02-28 21:39:27 +01:00
parent cd3c6fd71f
commit 18be34b336
3 changed files with 27 additions and 14 deletions

View File

@@ -2,10 +2,10 @@
[keybindings] [keybindings]
[keybindings.common] [keybindings.common]
save = [":w", "ctrl+s"] save = ["ctrl+s"]
quit = [":q", "ctrl+q"] quit = ["ctrl+q"]
force_quit = [":q!", "ctrl+shift+q"] force_quit = ["ctrl+shift+q"]
save_and_quit = [":wq", "ctrl+shift+s"] save_and_quit = ["ctrl+shift+s"]
move_up = ["Up"] move_up = ["Up"]
move_down = ["Down"] move_down = ["Down"]
@@ -29,6 +29,7 @@ move_line_start = ["0"]
move_line_end = ["$"] move_line_end = ["$"]
move_first_line = ["gg"] move_first_line = ["gg"]
move_last_line = ["x"] move_last_line = ["x"]
enter_command_mode = [":", "ctrl+;"]
[keybindings.edit] [keybindings.edit]
exit_edit_mode = ["esc","ctrl+e"] exit_edit_mode = ["esc","ctrl+e"]
@@ -43,7 +44,10 @@ move_right = ["right"]
exit_command_mode = ["ctrl+g", "esc"] exit_command_mode = ["ctrl+g", "esc"]
command_execute = ["enter"] command_execute = ["enter"]
command_backspace = ["backspace"] command_backspace = ["backspace"]
enter_command_mode = [":", "ctrl+;"] save = ["w"]
quit = ["q"]
force_quit = ["q!"]
save_and_quit = ["wq"]
[colors] [colors]
theme = "dark" theme = "dark"

View File

@@ -272,6 +272,7 @@ impl Config {
} }
/// Checks if a key is bound to entering Command mode. /// Checks if a key is bound to entering Command mode.
/// This method is no longer used in event.rs since we now handle command mode entry only in read-only mode directly.
pub fn is_enter_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool { pub fn is_enter_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
if let Some(bindings) = self.keybindings.command.get("enter_command_mode") { if let Some(bindings) = self.keybindings.command.get("enter_command_mode") {
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers)) bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
@@ -280,6 +281,7 @@ impl Config {
} }
} }
/// Checks if a key is bound to exiting Command mode. /// Checks if a key is bound to exiting Command mode.
pub fn is_exit_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool { pub fn is_exit_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
if let Some(bindings) = self.keybindings.command.get("exit_command_mode") { if let Some(bindings) = self.keybindings.command.get("exit_command_mode") {

View File

@@ -67,16 +67,11 @@ impl EventHandler {
return Ok((false, String::new())); return Ok((false, String::new()));
} }
// Check for entering command mode from any other mode // Mode transitions and mode-specific handling
if config.is_enter_command_mode(key.code, key.modifiers) {
self.command_mode = true;
self.command_input.clear();
self.command_message.clear();
return Ok((false, String::new()));
}
// Mode transitions between edit mode and read-only mode
if self.is_edit_mode { if self.is_edit_mode {
// When in EDIT mode, we DON'T want to check for entering command mode
// as ':' should just be a normal character input
// Check for exiting edit mode // Check for exiting edit mode
if config.is_exit_edit_mode(key.code, key.modifiers) { if config.is_exit_edit_mode(key.code, key.modifiers) {
if form_state.has_unsaved_changes { if form_state.has_unsaved_changes {
@@ -108,6 +103,18 @@ impl EventHandler {
self.key_sequence_tracker.reset(); self.key_sequence_tracker.reset();
return Ok((false, result)); return Ok((false, result));
} else { } else {
// In READ-ONLY mode, we DO want to check for entering command mode
// Check for entering command mode (only in read-only mode)
// Use get_read_only_action_for_key instead of is_enter_command_mode
if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) {
if action == "enter_command_mode" {
self.command_mode = true;
self.command_input.clear();
self.command_message.clear();
return Ok((false, String::new()));
}
}
// Check for entering edit mode from read-only mode // Check for entering edit mode from read-only mode
if config.is_enter_edit_mode_before(key.code, key.modifiers) { if config.is_enter_edit_mode_before(key.code, key.modifiers) {
self.is_edit_mode = true; self.is_edit_mode = true;