fixed command mode trigger
This commit is contained in:
@@ -21,28 +21,6 @@ pub async fn handle_edit_event(
|
|||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
if *command_mode {
|
|
||||||
// Delegate to the command mode handler
|
|
||||||
let (should_exit, message, exit_command_mode) = handle_command_event(
|
|
||||||
key,
|
|
||||||
config,
|
|
||||||
form_state,
|
|
||||||
command_input,
|
|
||||||
command_message,
|
|
||||||
app_terminal,
|
|
||||||
is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
if exit_command_mode {
|
|
||||||
*command_mode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !message.is_empty() {
|
|
||||||
return Ok((should_exit, message));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match key.code {
|
match key.code {
|
||||||
KeyCode::Left => {
|
KeyCode::Left => {
|
||||||
form_state.current_cursor_pos = form_state.current_cursor_pos.saturating_sub(1);
|
form_state.current_cursor_pos = form_state.current_cursor_pos.saturating_sub(1);
|
||||||
@@ -61,6 +39,7 @@ pub async fn handle_edit_event(
|
|||||||
*command_mode = true;
|
*command_mode = true;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
command_message.clear();
|
command_message.clear();
|
||||||
|
return Ok((false, "".to_string()));
|
||||||
}
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
if config.is_exit_edit_mode(key.code, key.modifiers) {
|
if config.is_exit_edit_mode(key.code, key.modifiers) {
|
||||||
@@ -166,7 +145,6 @@ pub async fn handle_edit_event(
|
|||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*edit_mode_cooldown = false;
|
*edit_mode_cooldown = false;
|
||||||
Ok((false, command_message.clone()))
|
Ok((false, command_message.clone()))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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::modes::handlers::edit::handle_edit_event;
|
use crate::modes::handlers::edit::handle_edit_event;
|
||||||
|
use crate::modes::handlers::command_mode::handle_command_event;
|
||||||
|
|
||||||
pub struct EventHandler {
|
pub struct EventHandler {
|
||||||
pub command_mode: bool,
|
pub command_mode: bool,
|
||||||
@@ -46,6 +47,42 @@ impl EventHandler {
|
|||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
if let Event::Key(key) = event {
|
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) {
|
if !self.is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
|
||||||
// Determine which type of edit mode we're entering
|
// Determine which type of edit mode we're entering
|
||||||
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
|
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 {
|
match key.code {
|
||||||
KeyCode::Char(':') => {
|
|
||||||
self.command_mode = true;
|
|
||||||
self.command_input.clear();
|
|
||||||
self.command_message.clear();
|
|
||||||
}
|
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.command_mode = false;
|
self.command_mode = false;
|
||||||
self.command_input.clear();
|
self.command_input.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user