command mode keybindings propery done
This commit is contained in:
@@ -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"
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,19 +19,15 @@ 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
|
|
||||||
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) {
|
if config.is_exit_command_mode(key.code, key.modifiers) {
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
*command_message = "".to_string();
|
*command_message = "".to_string();
|
||||||
return Ok((false, "".to_string(), true));
|
return Ok((false, "".to_string(), true));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
KeyCode::Enter => {
|
// Execute command (via configurable keybinding, defaults to Enter)
|
||||||
// Execute the command
|
if config.is_command_execute(key.code, key.modifiers) {
|
||||||
return process_command(
|
return process_command(
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
@@ -44,23 +39,23 @@ pub async fn handle_command_event(
|
|||||||
total_count,
|
total_count,
|
||||||
).await;
|
).await;
|
||||||
}
|
}
|
||||||
KeyCode::Char(c) => {
|
|
||||||
// In command mode, all character keys should be treated as text input
|
// Backspace (via configurable keybinding, defaults to Backspace)
|
||||||
// NOT as potential keybindings
|
if config.is_command_backspace(key.code, key.modifiers) {
|
||||||
command_input.push(c);
|
|
||||||
return Ok((false, "".to_string(), false));
|
|
||||||
}
|
|
||||||
KeyCode::Backspace => {
|
|
||||||
command_input.pop();
|
command_input.pop();
|
||||||
return Ok((false, "".to_string(), false));
|
return Ok((false, "".to_string(), false));
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
// Ignore other keys - don't process them as 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);
|
||||||
return Ok((false, "".to_string(), false));
|
return Ok((false, "".to_string(), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default case - nothing matched
|
// Ignore all other keys
|
||||||
Ok((false, "".to_string(), false))
|
Ok((false, "".to_string(), false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user