edit mode fallbag for not config

This commit is contained in:
filipriec
2025-02-28 17:54:45 +01:00
parent 1bf5eda854
commit 7403a6399d

View File

@@ -47,9 +47,12 @@ pub async fn handle_edit_event(
return Ok((false, "".to_string())); return Ok((false, "".to_string()));
} }
// Try to match against 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;
if key.modifiers.is_empty() { if key.modifiers.is_empty() {
key_sequence_tracker.add_key(key.code); key_sequence_tracker.add_key(key.code);
let sequence = key_sequence_tracker.get_sequence(); let sequence = key_sequence_tracker.get_sequence();
@@ -65,12 +68,14 @@ pub async fn handle_edit_event(
command_message, command_message,
app_terminal, app_terminal,
).await?; ).await?;
handled_by_config = true;
return Ok((false, result)); return Ok((false, 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((false, command_message.clone())); return Ok((false, command_message.clone()));
} }
@@ -87,6 +92,7 @@ pub async fn handle_edit_event(
command_message, command_message,
app_terminal, app_terminal,
).await?; ).await?;
handled_by_config = true;
return Ok((false, result)); return Ok((false, result));
} }
} }
@@ -102,27 +108,32 @@ pub async fn handle_edit_event(
command_message, command_message,
app_terminal, app_terminal,
).await?; ).await?;
handled_by_config = true;
return Ok((false, result)); return Ok((false, result));
} }
} }
// If not handled by action mappings, handle edit-specific behavior // 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( handle_edit_specific_input(
key, key,
form_state, form_state,
ideal_cursor_column, ideal_cursor_column,
); );
}
*edit_mode_cooldown = false; *edit_mode_cooldown = false;
Ok((false, command_message.clone())) Ok((false, command_message.clone()))
} }
// Handle edit-specific key input (character input, backspace, delete) // Handle edit-specific key input as a fallback (character input, backspace, delete)
fn handle_edit_specific_input( fn handle_edit_specific_input(
key: KeyEvent, key: KeyEvent,
form_state: &mut FormState, form_state: &mut FormState,
ideal_cursor_column: &mut usize, ideal_cursor_column: &mut usize,
) { ) {
// This is now explicitly a fallback function for default edit behavior
match key.code { match key.code {
KeyCode::Char(c) => { KeyCode::Char(c) => {
// Character input // Character input
@@ -313,7 +324,7 @@ async fn execute_edit_action(
} }
Ok("".to_string()) Ok("".to_string())
} }
// Edit-specific actions (if you want to add keybindings for these operations) // Edit-specific actions that can be bound to keys
"delete_char_forward" => { "delete_char_forward" => {
let cursor_pos = form_state.current_cursor_pos; let cursor_pos = form_state.current_cursor_pos;
let field_value = form_state.get_current_input_mut(); let field_value = form_state.get_current_input_mut();
@@ -341,6 +352,11 @@ async fn execute_edit_action(
} }
Ok("".to_string()) Ok("".to_string())
} }
"insert_char" => {
// This could be expanded to allow configurable character insertion
// For now, it's a placeholder that would need additional parameters
Ok("Character insertion requires configuration".to_string())
}
"next_field" => { "next_field" => {
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(); form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
let current_input = form_state.get_current_input(); let current_input = form_state.get_current_input();
@@ -359,7 +375,7 @@ async fn execute_edit_action(
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos); form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
Ok("".to_string()) Ok("".to_string())
} }
// Add more edit mode actions as needed // Fallback for unrecognized actions
_ => Ok(format!("Unknown action: {}", action)), _ => Ok(format!("Unknown action: {}", action)),
} }
} }