command mode keybindings propery done
This commit is contained in:
@@ -6,8 +6,6 @@ quit = [":q", "ctrl+q"]
|
||||
force_quit = [":q!", "ctrl+shift+q"]
|
||||
save_and_quit = [":wq", "ctrl+shift+s"]
|
||||
|
||||
enter_command_mode = [":", "ctrl+;"]
|
||||
|
||||
# MODE SPECIFIC
|
||||
# READ ONLY MODE
|
||||
enter_edit_mode_before = ["i"]
|
||||
@@ -36,9 +34,10 @@ next_field = ["tab", "enter"]
|
||||
prev_field = ["shift+tab", "backtab"]
|
||||
|
||||
# COMMAND MODE
|
||||
enter_command_mode = [":", "ctrl+;"]
|
||||
exit_command_mode = ["ctrl+g", "esc"]
|
||||
command_execute = ["enter"]
|
||||
command_backspace = ["backspace"]
|
||||
exit_command_mode = ["ctrl+g", "esc"]
|
||||
|
||||
[colors]
|
||||
theme = "dark"
|
||||
|
||||
@@ -300,4 +300,22 @@ impl Config {
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||
use crate::tui::terminal::AppTerminal;
|
||||
use crate::config::config::Config;
|
||||
use crate::ui::handlers::form::FormState;
|
||||
use crate::config::key_sequences::KeySequenceTracker;
|
||||
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
|
||||
|
||||
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>> {
|
||||
// Return value: (should_exit, message, should_exit_command_mode)
|
||||
|
||||
// ONLY check for command mode specific actions
|
||||
// This is a limited set of actions, not all keybindings
|
||||
match key.code {
|
||||
// Check for exit_command_mode action
|
||||
KeyCode::Esc | KeyCode::Char('g') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
if config.is_exit_command_mode(key.code, key.modifiers) {
|
||||
command_input.clear();
|
||||
*command_message = "".to_string();
|
||||
return Ok((false, "".to_string(), true));
|
||||
}
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// Execute the command
|
||||
return process_command(
|
||||
config,
|
||||
form_state,
|
||||
command_input,
|
||||
command_message,
|
||||
app_terminal,
|
||||
is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await;
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
// In command mode, all character keys should be treated as text input
|
||||
// NOT as potential keybindings
|
||||
// Exit command mode (via configurable keybinding)
|
||||
if config.is_exit_command_mode(key.code, key.modifiers) {
|
||||
command_input.clear();
|
||||
*command_message = "".to_string();
|
||||
return Ok((false, "".to_string(), true));
|
||||
}
|
||||
|
||||
// Execute command (via configurable keybinding, defaults to Enter)
|
||||
if config.is_command_execute(key.code, key.modifiers) {
|
||||
return process_command(
|
||||
config,
|
||||
form_state,
|
||||
command_input,
|
||||
command_message,
|
||||
app_terminal,
|
||||
is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await;
|
||||
}
|
||||
|
||||
// Backspace (via configurable keybinding, defaults to Backspace)
|
||||
if config.is_command_backspace(key.code, key.modifiers) {
|
||||
command_input.pop();
|
||||
return Ok((false, "".to_string(), false));
|
||||
}
|
||||
|
||||
// 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);
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user