finally working properly config parsing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// src/modes/handlers/read_only.rs
|
||||
|
||||
use crossterm::event::{KeyEvent, KeyCode};
|
||||
use crossterm::event::{KeyEvent};
|
||||
use crate::config::config::Config;
|
||||
use crate::ui::handlers::form::FormState;
|
||||
use crate::config::key_sequences::KeySequenceTracker;
|
||||
@@ -13,6 +13,7 @@ enum CharType {
|
||||
Punctuation,
|
||||
}
|
||||
|
||||
// Replace your current handle_read_only_event with this generalized version
|
||||
pub async fn handle_read_only_event(
|
||||
key: KeyEvent,
|
||||
config: &Config,
|
||||
@@ -25,14 +26,38 @@ pub async fn handle_read_only_event(
|
||||
edit_mode_cooldown: &mut bool,
|
||||
ideal_cursor_column: &mut usize,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
// Handle key sequences and actions
|
||||
if let KeyCode::Char(_) = key.code {
|
||||
if key.modifiers.is_empty() {
|
||||
key_sequence_tracker.add_key(key.code);
|
||||
let sequence = key_sequence_tracker.get_sequence();
|
||||
let sequence_str = key_sequence_tracker.sequence_to_string();
|
||||
// Always add the key to the sequence tracker if no modifiers
|
||||
// This tracks ALL keys, not just character keys
|
||||
if key.modifiers.is_empty() {
|
||||
key_sequence_tracker.add_key(key.code);
|
||||
let sequence = key_sequence_tracker.get_sequence();
|
||||
|
||||
if let Some(action) = config.matches_key_sequence(&sequence) {
|
||||
// Try to match the current sequence against all bindings
|
||||
if let Some(action) = config.matches_key_sequence_generalized(&sequence) {
|
||||
let result = execute_action(
|
||||
action,
|
||||
form_state,
|
||||
ideal_cursor_column,
|
||||
key_sequence_tracker,
|
||||
command_message,
|
||||
current_position,
|
||||
total_count,
|
||||
app_terminal,
|
||||
).await?;
|
||||
key_sequence_tracker.reset();
|
||||
return Ok((false, result));
|
||||
}
|
||||
|
||||
// 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
|
||||
return Ok((false, command_message.clone()));
|
||||
}
|
||||
|
||||
// Since it's not part of a multi-key sequence, check for a direct action
|
||||
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_action(
|
||||
action,
|
||||
form_state,
|
||||
@@ -46,33 +71,11 @@ pub async fn handle_read_only_event(
|
||||
key_sequence_tracker.reset();
|
||||
return Ok((false, result));
|
||||
}
|
||||
|
||||
if sequence.len() == 1 {
|
||||
let is_prefix = is_prefix_of_multikey_binding(&sequence_str, config);
|
||||
if !is_prefix {
|
||||
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
||||
let result = execute_action(
|
||||
action,
|
||||
form_state,
|
||||
ideal_cursor_column,
|
||||
key_sequence_tracker,
|
||||
command_message,
|
||||
current_position,
|
||||
total_count,
|
||||
app_terminal,
|
||||
).await?;
|
||||
key_sequence_tracker.reset();
|
||||
return Ok((false, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
key_sequence_tracker.reset();
|
||||
}
|
||||
} else {
|
||||
// If modifiers are pressed, check for direct key bindings
|
||||
key_sequence_tracker.reset();
|
||||
|
||||
// Handle special keys through config
|
||||
if let Some(action) = config.get_action_for_key(key.code, key.modifiers) {
|
||||
let result = execute_action(
|
||||
action,
|
||||
@@ -86,15 +89,15 @@ pub async fn handle_read_only_event(
|
||||
).await?;
|
||||
return Ok((false, result));
|
||||
}
|
||||
}
|
||||
|
||||
// Provide feedback when not in edit mode and cooldown expired
|
||||
if !*edit_mode_cooldown {
|
||||
let default_key = "i".to_string();
|
||||
let edit_key = config.keybindings.get("enter_edit_mode")
|
||||
.and_then(|keys| keys.first())
|
||||
.unwrap_or(&default_key);
|
||||
*command_message = format!("Read-only mode - press {} to edit", edit_key);
|
||||
}
|
||||
// Show a helpful message when no binding was found
|
||||
if !*edit_mode_cooldown {
|
||||
let default_key = "i".to_string();
|
||||
let edit_key = config.keybindings.get("enter_edit_mode_before")
|
||||
.and_then(|keys| keys.first())
|
||||
.unwrap_or(&default_key);
|
||||
*command_message = format!("Read-only mode - press {} to edit", edit_key);
|
||||
}
|
||||
|
||||
Ok((false, command_message.clone()))
|
||||
@@ -184,7 +187,6 @@ async fn execute_action(
|
||||
Ok("".to_string())
|
||||
}
|
||||
"move_left" => {
|
||||
let current_input = form_state.get_current_input();
|
||||
let current_pos = form_state.current_cursor_pos;
|
||||
form_state.current_cursor_pos = current_pos.saturating_sub(1);
|
||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
||||
|
||||
Reference in New Issue
Block a user