fixed command mode trigger
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::tui::terminal::AppTerminal;
|
||||
use crate::config::config::Config;
|
||||
use crate::ui::handlers::form::FormState;
|
||||
use crate::modes::handlers::edit::handle_edit_event;
|
||||
use crate::modes::handlers::command_mode::handle_command_event;
|
||||
|
||||
pub struct EventHandler {
|
||||
pub command_mode: bool,
|
||||
@@ -46,6 +47,42 @@ impl EventHandler {
|
||||
current_position: &mut u64,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
if let Event::Key(key) = event {
|
||||
// Handle command mode first, regardless of the current editing mode
|
||||
if self.command_mode {
|
||||
let (should_exit, message, exit_command_mode) = handle_command_event(
|
||||
key,
|
||||
config,
|
||||
form_state,
|
||||
&mut self.command_input,
|
||||
&mut self.command_message,
|
||||
app_terminal,
|
||||
is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
|
||||
if exit_command_mode {
|
||||
self.command_mode = false;
|
||||
}
|
||||
|
||||
if !message.is_empty() {
|
||||
return Ok((should_exit, message));
|
||||
}
|
||||
|
||||
// If we're still in command mode, don't process other keys
|
||||
if self.command_mode {
|
||||
return Ok((false, "".to_string()));
|
||||
}
|
||||
}
|
||||
// Handle special case: Entering command mode with ":"
|
||||
else if key.code == KeyCode::Char(':') {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
self.command_message.clear();
|
||||
return Ok((false, "".to_string()));
|
||||
}
|
||||
|
||||
// Handle mode transitions
|
||||
if !self.is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
|
||||
// Determine which type of edit mode we're entering
|
||||
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
|
||||
@@ -317,13 +354,8 @@ impl EventHandler {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
// Handle other keys (e.g., command mode)
|
||||
// Handle other keys in read-only mode
|
||||
match key.code {
|
||||
KeyCode::Char(':') => {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
self.command_message.clear();
|
||||
}
|
||||
KeyCode::Esc => {
|
||||
self.command_mode = false;
|
||||
self.command_input.clear();
|
||||
|
||||
Reference in New Issue
Block a user