diff --git a/client/src/modes/handlers/edit.rs b/client/src/modes/handlers/edit.rs index 9883303..1fdf75b 100644 --- a/client/src/modes/handlers/edit.rs +++ b/client/src/modes/handlers/edit.rs @@ -16,8 +16,6 @@ pub async fn handle_edit_event_internal( ) -> Result> { // Try to match against configured action mappings first let mut key_sequence_tracker = KeySequenceTracker::new(800); - - // Phase 1: Check for configured key bindings let mut handled_by_config = false; if key.modifiers.is_empty() { @@ -26,20 +24,16 @@ pub async fn handle_edit_event_internal( // Try to match the current sequence against all bindings if let Some(action) = config.matches_key_sequence_generalized(&sequence) { - let result = execute_edit_action( + return execute_edit_action( action, form_state, ideal_cursor_column, - command_message, - ).await?; - handled_by_config = true; - return Ok(result); + ).await; } // Check if this might be a prefix of a longer sequence if config.is_key_sequence_prefix(&sequence) { // If it's a prefix, wait for more keys - handled_by_config = true; return Ok(command_message.clone()); } @@ -47,39 +41,30 @@ pub async fn handle_edit_event_internal( if sequence.len() == 1 && !config.is_key_sequence_prefix(&sequence) { // Try to handle it as a single key if let Some(action) = config.get_action_for_key(key.code, key.modifiers) { - let result = execute_edit_action( + return execute_edit_action( action, form_state, ideal_cursor_column, - command_message, - ).await?; - handled_by_config = true; - return Ok(result); + ).await; } } } else { // If modifiers are pressed, check for direct key bindings if let Some(action) = config.get_action_for_key(key.code, key.modifiers) { - let result = execute_edit_action( + return execute_edit_action( action, form_state, ideal_cursor_column, - command_message, - ).await?; - handled_by_config = true; - return Ok(result); + ).await; } } - // Phase 2: Fallback to default hardcoded behavior only if not handled by configuration - if !handled_by_config { - // This is now explicitly a fallback for when no config match is found - handle_edit_specific_input( - key, - form_state, - ideal_cursor_column, - ); - } + // If we get here, no key mapping was found, so we handle fallback behavior + handle_edit_specific_input( + key, + form_state, + ideal_cursor_column, + ); Ok(command_message.clone()) } @@ -90,16 +75,16 @@ pub async fn handle_edit_event( key: KeyEvent, config: &Config, form_state: &mut FormState, - is_edit_mode: &mut bool, + _is_edit_mode: &mut bool, edit_mode_cooldown: &mut bool, ideal_cursor_column: &mut usize, command_message: &mut String, - command_mode: &mut bool, - command_input: &mut String, - app_terminal: &mut AppTerminal, - is_saved: &mut bool, - current_position: &mut u64, - total_count: u64, + _command_mode: &mut bool, + _command_input: &mut String, + _app_terminal: &mut AppTerminal, + _is_saved: &mut bool, + _current_position: &mut u64, + _total_count: u64, ) -> Result<(bool, String), Box> { // This function should ideally not be called anymore - everything should go through event.rs // Log a warning that this code path is deprecated @@ -195,7 +180,6 @@ async fn execute_edit_action( action: &str, form_state: &mut FormState, ideal_cursor_column: &mut usize, - command_message: &mut String, ) -> Result> { match action { // Navigation actions diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index e469854..4ecf415 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -1,6 +1,6 @@ // src/modes/handlers/event.rs -use crossterm::event::{Event, KeyCode, KeyEvent}; +use crossterm::event::{Event, KeyEvent}; use crossterm::cursor::SetCursorStyle; use crate::tui::terminal::AppTerminal; use crate::config::config::Config; @@ -97,10 +97,16 @@ impl EventHandler { } // Handle edit mode events - return self.handle_edit_mode_internal( - key, config, app_terminal, form_state, - is_saved, current_position, total_count - ).await; + let result = edit::handle_edit_event_internal( + key, + config, + form_state, + &mut self.ideal_cursor_column, + &mut self.command_message, + ).await?; + + self.key_sequence_tracker.reset(); + return Ok((false, result)); } else { // Check for entering edit mode from read-only mode if config.is_enter_edit_mode(key.code, key.modifiers) { @@ -119,9 +125,17 @@ impl EventHandler { } // Handle read-only mode events - return self.handle_read_only_mode_internal( - key, config, app_terminal, form_state, - current_position, total_count + return read_only::handle_read_only_event( + key, + config, + form_state, + &mut self.key_sequence_tracker, + current_position, + total_count, + app_terminal, + &mut self.command_message, + &mut self.edit_mode_cooldown, + &mut self.ideal_cursor_column, ).await; } } @@ -129,51 +143,4 @@ impl EventHandler { self.edit_mode_cooldown = false; Ok((false, self.command_message.clone())) } - - async fn handle_edit_mode_internal( - &mut self, - key: KeyEvent, - config: &Config, - app_terminal: &mut AppTerminal, - form_state: &mut FormState, - is_saved: &mut bool, - current_position: &mut u64, - total_count: u64, - ) -> Result<(bool, String), Box> { - // We're calling the edit handler, but we know we're not in command mode - // and we've already handled exit_edit_mode transition above - let result = edit::handle_edit_event_internal( - key, - config, - form_state, - &mut self.ideal_cursor_column, - &mut self.command_message, - ).await?; - - self.key_sequence_tracker.reset(); - Ok((false, result)) - } - - async fn handle_read_only_mode_internal( - &mut self, - key: KeyEvent, - config: &Config, - app_terminal: &mut AppTerminal, - form_state: &mut FormState, - current_position: &mut u64, - total_count: u64, - ) -> Result<(bool, String), Box> { - read_only::handle_read_only_event( - key, - config, - form_state, - &mut self.key_sequence_tracker, - current_position, - total_count, - app_terminal, - &mut self.command_message, - &mut self.edit_mode_cooldown, - &mut self.ideal_cursor_column, - ).await - } } diff --git a/client/src/modes/handlers/read_only.rs b/client/src/modes/handlers/read_only.rs index 37e16c0..a95357a 100644 --- a/client/src/modes/handlers/read_only.rs +++ b/client/src/modes/handlers/read_only.rs @@ -314,18 +314,6 @@ async fn execute_action( } } -fn is_prefix_of_multikey_binding(sequence: &str, config: &Config) -> bool { - for (_, bindings) in &config.keybindings { - for binding in bindings { - if binding.contains('+') { continue; } - if binding.len() > sequence.len() && binding.starts_with(sequence) { - return true; - } - } - } - false -} - fn get_char_type(c: char) -> CharType { if c.is_whitespace() { CharType::Whitespace