fixes 5
This commit is contained in:
@@ -17,8 +17,7 @@ use crate::modes::{
|
||||
};
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use canvas::{canvas::CanvasAction, dispatcher::ActionDispatcher};
|
||||
use canvas::canvas::CanvasState; // Only need this import now
|
||||
use canvas::FormEditor;
|
||||
use crate::state::{
|
||||
app::{
|
||||
buffer::{AppView, BufferState},
|
||||
@@ -775,9 +774,11 @@ impl EventHandler {
|
||||
|
||||
// Try canvas action for form first
|
||||
if app_state.ui.show_form {
|
||||
let mut editor = FormEditor::new(form_state.clone());
|
||||
if let Ok(Some(canvas_message)) = self.handle_form_canvas_action(
|
||||
key_event,
|
||||
form_state,
|
||||
&mut editor,
|
||||
config,
|
||||
false,
|
||||
).await {
|
||||
return Ok(EventOutcome::Ok(canvas_message));
|
||||
@@ -864,9 +865,11 @@ impl EventHandler {
|
||||
|
||||
// Try canvas action for form first
|
||||
if app_state.ui.show_form {
|
||||
let mut editor = FormEditor::new(form_state.clone());
|
||||
if let Ok(Some(canvas_message)) = self.handle_form_canvas_action(
|
||||
key_event,
|
||||
form_state,
|
||||
&mut editor,
|
||||
config,
|
||||
true,
|
||||
).await {
|
||||
if !canvas_message.is_empty() {
|
||||
@@ -1101,64 +1104,60 @@ impl EventHandler {
|
||||
async fn handle_form_canvas_action(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
form_state: &mut FormState,
|
||||
editor: &mut FormEditor<FormState>,
|
||||
config: &Config,
|
||||
is_edit_mode: bool,
|
||||
) -> Result<Option<String>> {
|
||||
let canvas_config = canvas::config::CanvasConfig::load();
|
||||
|
||||
// PRIORITY 1: Handle character insertion in edit mode FIRST
|
||||
use crossterm::event::KeyCode;
|
||||
|
||||
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()));
|
||||
}
|
||||
editor.insert_char(c)?;
|
||||
return Ok(Some(format!("Inserted '{}'", c)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use your config to resolve actions
|
||||
if let Some(action) = config.get_edit_action_for_key(key_event.code, key_event.modifiers) {
|
||||
match action {
|
||||
"delete_char_backward" => { editor.delete_backward()?; return Ok(Some("Deleted backward".to_string())); }
|
||||
"delete_char_forward" => { editor.delete_forward()?; return Ok(Some("Deleted forward".to_string())); }
|
||||
"move_left" => { editor.move_left()?; return Ok(Some("Moved left".to_string())); }
|
||||
"move_right" => { editor.move_right()?; return Ok(Some("Moved right".to_string())); }
|
||||
"move_up" => { editor.move_up()?; return Ok(Some("Moved up".to_string())); }
|
||||
"move_down" => { editor.move_down()?; return Ok(Some("Moved down".to_string())); }
|
||||
|
||||
"move_line_start" => { editor.move_line_start(); return Ok(Some("Line start".to_string())); }
|
||||
"move_line_end" => { editor.move_line_end(); return Ok(Some("Line end".to_string())); }
|
||||
"move_word_next" => { editor.move_word_next(); return Ok(Some("Next word".to_string())); }
|
||||
"move_word_prev" => { editor.move_word_prev(); return Ok(Some("Prev word".to_string())); }
|
||||
"move_word_end" => { editor.move_word_end(); return Ok(Some("Word end".to_string())); }
|
||||
"move_word_end_prev" => { editor.move_word_end_prev(); return Ok(Some("Prev word end".to_string())); }
|
||||
|
||||
"next_field" => { editor.next_field()?; return Ok(Some("Next field".to_string())); }
|
||||
"prev_field" => { editor.prev_field()?; return Ok(Some("Prev field".to_string())); }
|
||||
"open_suggestions" => {
|
||||
let field_index = editor.current_field();
|
||||
editor.open_suggestions(field_index);
|
||||
return Ok(Some("Opened suggestions".to_string()));
|
||||
}
|
||||
"apply_suggestion" | "enter_decider" => {
|
||||
if let Some(s) = editor.apply_suggestion() {
|
||||
return Ok(Some(format!("Applied suggestion: {}", s)));
|
||||
} else {
|
||||
return Ok(Some("No suggestion applied".to_string()));
|
||||
}
|
||||
}
|
||||
"exit" | "exit_edit_mode" => {
|
||||
editor.exit_edit_mode()?;
|
||||
return Ok(Some("Exited edit mode".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,
|
||||
);
|
||||
|
||||
if let Some(action_str) = action_str {
|
||||
// Skip mode transition actions - let the main event handler deal with them
|
||||
if Self::is_mode_transition_action(action_str) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
// Execute the config-mapped action
|
||||
let canvas_action = CanvasAction::from_string(action_str);
|
||||
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("Canvas action failed".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No action found
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user