From ebe4adaa5d6dec58ab01a1c214cbda3637cd30f3 Mon Sep 17 00:00:00 2001 From: Priec Date: Thu, 31 Jul 2025 13:39:38 +0200 Subject: [PATCH] bug is present, i cant type or move in canvas from client --- client/.gitignore | 1 + client/canvas_config.toml | 52 ------------------------------ client/src/modes/handlers/event.rs | 49 ++++++++++++++-------------- 3 files changed, 26 insertions(+), 76 deletions(-) create mode 100644 client/.gitignore delete mode 100644 client/canvas_config.toml diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..24e2a7a --- /dev/null +++ b/client/.gitignore @@ -0,0 +1 @@ +canvas_config.toml.txt diff --git a/client/canvas_config.toml b/client/canvas_config.toml deleted file mode 100644 index 09a4966..0000000 --- a/client/canvas_config.toml +++ /dev/null @@ -1,52 +0,0 @@ -[keybindings.edit] -# Required -move_right = ["Right", "l"] -delete_char_backward = ["Backspace"] -next_field = ["Tab", "Enter"] -move_up = ["Up", "k"] -move_down = ["Down", "j"] -prev_field = ["Shift+Tab"] -move_left = ["Left", "h"] -# Optional -move_last_line = ["Ctrl+End", "G"] -delete_char_forward = ["Delete"] -move_word_prev = ["Ctrl+Left", "b"] -move_word_end = ["e"] -move_word_end_prev = ["ge"] -move_first_line = ["Ctrl+Home", "gg"] -move_word_next = ["Ctrl+Right", "w"] -move_line_start = ["Home", "0"] -move_line_end = ["End", "$"] - -[keybindings.highlight] -# Required -move_left = ["h", "Left"] -move_right = ["l", "Right"] -move_up = ["k", "Up"] -move_down = ["j", "Down"] -# Optional -move_word_next = ["w"] -move_line_start = ["0"] -move_line_end = ["$"] -move_word_prev = ["b"] -move_word_end = ["e"] - -[keybindings.read_only] -# Required -move_up = ["k", "Up"] -move_left = ["h", "Left"] -move_right = ["l", "Right"] -move_down = ["j", "Down"] -# Optional -move_line_end = ["$"] -move_word_next = ["w"] -next_field = ["Tab"] -move_word_prev = ["b"] -move_word_end = ["e"] -move_last_line = ["G"] -move_word_end_prev = ["ge"] -move_line_start = ["0"] -move_first_line = ["gg"] -prev_field = ["Shift+Tab"] - - diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 7e560dc..fadcc6e 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -45,6 +45,7 @@ use crate::ui::handlers::rat_state::UiStateHandler; use anyhow::Result; use common::proto::komp_ac::search::search_response::Hit; use crossterm::cursor::SetCursorStyle; +use crossterm::event::KeyModifiers; use crossterm::event::{Event, KeyCode, KeyEvent}; use tokio::sync::mpsc; use tokio::sync::mpsc::unbounded_channel; @@ -776,7 +777,6 @@ impl EventHandler { if app_state.ui.show_form { if let Ok(Some(canvas_message)) = self.handle_form_canvas_action( key_event, - config, form_state, false, ).await { @@ -866,7 +866,6 @@ impl EventHandler { if app_state.ui.show_form { if let Ok(Some(canvas_message)) = self.handle_form_canvas_action( key_event, - config, form_state, true, ).await { @@ -1102,18 +1101,39 @@ impl EventHandler { async fn handle_form_canvas_action( &mut self, key_event: KeyEvent, - _config: &Config, form_state: &mut FormState, is_edit_mode: bool, ) -> Result> { let canvas_config = canvas::config::CanvasConfig::load(); - // Get action from config - handles all modes (edit/read-only/suggestions) + // PRIORITY 1: Handle character insertion in edit mode FIRST + if is_edit_mode { + if let KeyCode::Char(c) = key_event.code { + // Only insert if it's not a special modifier combination + if key_event.modifiers.is_empty() || key_event.modifiers == KeyModifiers::SHIFT { + let canvas_action = CanvasAction::InsertChar(c); + match ActionDispatcher::dispatch( + canvas_action, + form_state, + &mut self.ideal_cursor_column, + ).await { + Ok(result) => { + return Ok(Some(result.message().unwrap_or("").to_string())); + } + Err(_) => { + return Ok(Some("Character insertion failed".to_string())); + } + } + } + } + } + + // PRIORITY 2: Handle config-mapped actions for non-character keys let action_str = canvas_config.get_action_for_key( key_event.code, key_event.modifiers, is_edit_mode, - form_state.autocomplete_active + form_state.autocomplete_active, ); if let Some(action_str) = action_str { @@ -1138,25 +1158,6 @@ impl EventHandler { } } - // Handle character insertion for edit mode (not in config) - if is_edit_mode { - if let KeyCode::Char(c) = key_event.code { - let canvas_action = CanvasAction::InsertChar(c); - match ActionDispatcher::dispatch( - canvas_action, - form_state, - &mut self.ideal_cursor_column, - ).await { - Ok(result) => { - return Ok(Some(result.message().unwrap_or("").to_string())); - } - Err(_) => { - return Ok(Some("Character insertion failed".to_string())); - } - } - } - } - // No action found Ok(None) }