fixing warnings
This commit is contained in:
@@ -16,8 +16,6 @@ pub async fn handle_edit_event_internal(
|
|||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
// Try to match against configured action mappings first
|
// Try to match against configured action mappings first
|
||||||
let mut key_sequence_tracker = KeySequenceTracker::new(800);
|
let mut key_sequence_tracker = KeySequenceTracker::new(800);
|
||||||
|
|
||||||
// Phase 1: Check for configured key bindings
|
|
||||||
let mut handled_by_config = false;
|
let mut handled_by_config = false;
|
||||||
|
|
||||||
if key.modifiers.is_empty() {
|
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
|
// Try to match the current sequence against all bindings
|
||||||
if let Some(action) = config.matches_key_sequence_generalized(&sequence) {
|
if let Some(action) = config.matches_key_sequence_generalized(&sequence) {
|
||||||
let result = execute_edit_action(
|
return execute_edit_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
command_message,
|
).await;
|
||||||
).await?;
|
|
||||||
handled_by_config = true;
|
|
||||||
return Ok(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this might be a prefix of a longer sequence
|
// Check if this might be a prefix of a longer sequence
|
||||||
if config.is_key_sequence_prefix(&sequence) {
|
if config.is_key_sequence_prefix(&sequence) {
|
||||||
// If it's a prefix, wait for more keys
|
// If it's a prefix, wait for more keys
|
||||||
handled_by_config = true;
|
|
||||||
return Ok(command_message.clone());
|
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) {
|
if sequence.len() == 1 && !config.is_key_sequence_prefix(&sequence) {
|
||||||
// Try to handle it as a single key
|
// Try to handle it as a single key
|
||||||
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
||||||
let result = execute_edit_action(
|
return execute_edit_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
command_message,
|
).await;
|
||||||
).await?;
|
|
||||||
handled_by_config = true;
|
|
||||||
return Ok(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If modifiers are pressed, check for direct key bindings
|
// If modifiers are pressed, check for direct key bindings
|
||||||
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
||||||
let result = execute_edit_action(
|
return execute_edit_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
command_message,
|
).await;
|
||||||
).await?;
|
|
||||||
handled_by_config = true;
|
|
||||||
return Ok(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase 2: Fallback to default hardcoded behavior only if not handled by configuration
|
// If we get here, no key mapping was found, so we handle fallback behavior
|
||||||
if !handled_by_config {
|
handle_edit_specific_input(
|
||||||
// This is now explicitly a fallback for when no config match is found
|
key,
|
||||||
handle_edit_specific_input(
|
form_state,
|
||||||
key,
|
ideal_cursor_column,
|
||||||
form_state,
|
);
|
||||||
ideal_cursor_column,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(command_message.clone())
|
Ok(command_message.clone())
|
||||||
}
|
}
|
||||||
@@ -90,16 +75,16 @@ pub async fn handle_edit_event(
|
|||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
is_edit_mode: &mut bool,
|
_is_edit_mode: &mut bool,
|
||||||
edit_mode_cooldown: &mut bool,
|
edit_mode_cooldown: &mut bool,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
command_mode: &mut bool,
|
_command_mode: &mut bool,
|
||||||
command_input: &mut String,
|
_command_input: &mut String,
|
||||||
app_terminal: &mut AppTerminal,
|
_app_terminal: &mut AppTerminal,
|
||||||
is_saved: &mut bool,
|
_is_saved: &mut bool,
|
||||||
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>> {
|
||||||
// This function should ideally not be called anymore - everything should go through event.rs
|
// This function should ideally not be called anymore - everything should go through event.rs
|
||||||
// Log a warning that this code path is deprecated
|
// Log a warning that this code path is deprecated
|
||||||
@@ -195,7 +180,6 @@ async fn execute_edit_action(
|
|||||||
action: &str,
|
action: &str,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
command_message: &mut String,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
match action {
|
match action {
|
||||||
// Navigation actions
|
// Navigation actions
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/modes/handlers/event.rs
|
// src/modes/handlers/event.rs
|
||||||
|
|
||||||
use crossterm::event::{Event, KeyCode, KeyEvent};
|
use crossterm::event::{Event, KeyEvent};
|
||||||
use crossterm::cursor::SetCursorStyle;
|
use crossterm::cursor::SetCursorStyle;
|
||||||
use crate::tui::terminal::AppTerminal;
|
use crate::tui::terminal::AppTerminal;
|
||||||
use crate::config::config::Config;
|
use crate::config::config::Config;
|
||||||
@@ -97,10 +97,16 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle edit mode events
|
// Handle edit mode events
|
||||||
return self.handle_edit_mode_internal(
|
let result = edit::handle_edit_event_internal(
|
||||||
key, config, app_terminal, form_state,
|
key,
|
||||||
is_saved, current_position, total_count
|
config,
|
||||||
).await;
|
form_state,
|
||||||
|
&mut self.ideal_cursor_column,
|
||||||
|
&mut self.command_message,
|
||||||
|
).await?;
|
||||||
|
|
||||||
|
self.key_sequence_tracker.reset();
|
||||||
|
return Ok((false, result));
|
||||||
} else {
|
} else {
|
||||||
// Check for entering edit mode from read-only mode
|
// Check for entering edit mode from read-only mode
|
||||||
if config.is_enter_edit_mode(key.code, key.modifiers) {
|
if config.is_enter_edit_mode(key.code, key.modifiers) {
|
||||||
@@ -119,9 +125,17 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle read-only mode events
|
// Handle read-only mode events
|
||||||
return self.handle_read_only_mode_internal(
|
return read_only::handle_read_only_event(
|
||||||
key, config, app_terminal, form_state,
|
key,
|
||||||
current_position, total_count
|
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;
|
).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,51 +143,4 @@ impl EventHandler {
|
|||||||
self.edit_mode_cooldown = false;
|
self.edit_mode_cooldown = false;
|
||||||
Ok((false, self.command_message.clone()))
|
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<dyn std::error::Error>> {
|
|
||||||
// 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<dyn std::error::Error>> {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
fn get_char_type(c: char) -> CharType {
|
||||||
if c.is_whitespace() {
|
if c.is_whitespace() {
|
||||||
CharType::Whitespace
|
CharType::Whitespace
|
||||||
|
|||||||
Reference in New Issue
Block a user