command mode keybindings propery done

This commit is contained in:
filipriec
2025-02-28 16:54:05 +01:00
parent bd83fb47e1
commit 1bf5eda854
3 changed files with 52 additions and 40 deletions

View File

@@ -6,8 +6,6 @@ quit = [":q", "ctrl+q"]
force_quit = [":q!", "ctrl+shift+q"] force_quit = [":q!", "ctrl+shift+q"]
save_and_quit = [":wq", "ctrl+shift+s"] save_and_quit = [":wq", "ctrl+shift+s"]
enter_command_mode = [":", "ctrl+;"]
# MODE SPECIFIC # MODE SPECIFIC
# READ ONLY MODE # READ ONLY MODE
enter_edit_mode_before = ["i"] enter_edit_mode_before = ["i"]
@@ -36,9 +34,10 @@ next_field = ["tab", "enter"]
prev_field = ["shift+tab", "backtab"] prev_field = ["shift+tab", "backtab"]
# COMMAND MODE # COMMAND MODE
enter_command_mode = [":", "ctrl+;"]
exit_command_mode = ["ctrl+g", "esc"]
command_execute = ["enter"] command_execute = ["enter"]
command_backspace = ["backspace"] command_backspace = ["backspace"]
exit_command_mode = ["ctrl+g", "esc"]
[colors] [colors]
theme = "dark" theme = "dark"

View File

@@ -300,4 +300,22 @@ impl Config {
false false
} }
pub fn is_command_execute(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
if let Some(bindings) = self.keybindings.get("command_execute") {
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
} else {
// Fall back to Enter key if no command_execute is defined
key == KeyCode::Enter && modifiers.is_empty()
}
}
pub fn is_command_backspace(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
if let Some(bindings) = self.keybindings.get("command_backspace") {
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
} else {
// Fall back to Backspace key if no command_backspace is defined
key == KeyCode::Backspace && modifiers.is_empty()
}
}
} }

View File

@@ -4,7 +4,6 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::tui::terminal::AppTerminal; use crate::tui::terminal::AppTerminal;
use crate::config::config::Config; use crate::config::config::Config;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use crate::config::key_sequences::KeySequenceTracker;
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest}; use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
pub async fn handle_command_event( pub async fn handle_command_event(
@@ -20,47 +19,43 @@ pub async fn handle_command_event(
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> { ) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
// Return value: (should_exit, message, should_exit_command_mode) // Return value: (should_exit, message, should_exit_command_mode)
// ONLY check for command mode specific actions // Exit command mode (via configurable keybinding)
// This is a limited set of actions, not all keybindings if config.is_exit_command_mode(key.code, key.modifiers) {
match key.code { command_input.clear();
// Check for exit_command_mode action *command_message = "".to_string();
KeyCode::Esc | KeyCode::Char('g') if key.modifiers.contains(KeyModifiers::CONTROL) => { return Ok((false, "".to_string(), true));
if config.is_exit_command_mode(key.code, key.modifiers) { }
command_input.clear();
*command_message = "".to_string(); // Execute command (via configurable keybinding, defaults to Enter)
return Ok((false, "".to_string(), true)); if config.is_command_execute(key.code, key.modifiers) {
} return process_command(
} config,
KeyCode::Enter => { form_state,
// Execute the command command_input,
return process_command( command_message,
config, app_terminal,
form_state, is_saved,
command_input, current_position,
command_message, total_count,
app_terminal, ).await;
is_saved, }
current_position,
total_count, // Backspace (via configurable keybinding, defaults to Backspace)
).await; if config.is_command_backspace(key.code, key.modifiers) {
} command_input.pop();
KeyCode::Char(c) => { return Ok((false, "".to_string(), false));
// In command mode, all character keys should be treated as text input }
// NOT as potential keybindings
// Regular character input - accept any character in command mode
if let KeyCode::Char(c) = key.code {
// Accept regular or shifted characters (e.g., 'a' or 'A')
if key.modifiers.is_empty() || key.modifiers == KeyModifiers::SHIFT {
command_input.push(c); command_input.push(c);
return Ok((false, "".to_string(), false)); return Ok((false, "".to_string(), false));
} }
KeyCode::Backspace => {
command_input.pop();
return Ok((false, "".to_string(), false));
}
_ => {
// Ignore other keys - don't process them as keybindings
return Ok((false, "".to_string(), false));
}
} }
// Default case - nothing matched // Ignore all other keys
Ok((false, "".to_string(), false)) Ok((false, "".to_string(), false))
} }