config now finally works
This commit is contained in:
@@ -1024,12 +1024,24 @@ impl EventHandler {
|
||||
async fn handle_form_canvas_action(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
config: &Config,
|
||||
_config: &Config, // Not used anymore - canvas has its own config
|
||||
form_state: &mut FormState,
|
||||
is_edit_mode: bool,
|
||||
) -> Result<Option<String>> {
|
||||
// Load canvas config (canvas_config.toml or vim defaults)
|
||||
let canvas_config = canvas::config::CanvasConfig::load();
|
||||
|
||||
// Handle suggestion actions first if suggestions are active
|
||||
if form_state.autocomplete_active {
|
||||
if let Some(action_str) = canvas_config.get_suggestion_action(key_event.code, key_event.modifiers) {
|
||||
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("Suggestion action failed".to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback hardcoded suggestion handling
|
||||
match key_event.code {
|
||||
KeyCode::Up => {
|
||||
if let Ok(result) = ActionDispatcher::dispatch(
|
||||
@@ -1071,15 +1083,16 @@ impl EventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// Check config mappings FIRST, before CanvasAction::from_key
|
||||
let action_str = if is_edit_mode {
|
||||
config.get_edit_action_for_key(key_event.code, key_event.modifiers)
|
||||
} else {
|
||||
config.get_read_only_action_for_key(key_event.code, key_event.modifiers)
|
||||
};
|
||||
// FIXED: Use canvas config instead of client config
|
||||
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 {
|
||||
// FIXED: Filter out mode transition actions - let legacy handlers deal with these
|
||||
// Filter out mode transition actions - let legacy handlers deal with these
|
||||
if Self::is_mode_transition_action(action_str) {
|
||||
return Ok(None); // Let legacy handler handle mode transitions
|
||||
}
|
||||
@@ -1094,14 +1107,13 @@ impl EventHandler {
|
||||
return Ok(Some(result.message().unwrap_or("").to_string()));
|
||||
}
|
||||
Err(_) => {
|
||||
return Ok(Some("Action failed".to_string()));
|
||||
return Ok(Some("Canvas action failed".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only try CanvasAction::from_key as a fallback, and be more selective
|
||||
// Fallback to automatic key handling for edit mode
|
||||
if is_edit_mode {
|
||||
// In edit mode, allow character insertion for unmapped keys
|
||||
if let Some(canvas_action) = CanvasAction::from_key(key_event.code) {
|
||||
match ActionDispatcher::dispatch(
|
||||
canvas_action,
|
||||
@@ -1112,7 +1124,7 @@ impl EventHandler {
|
||||
return Ok(Some(result.message().unwrap_or("").to_string()));
|
||||
}
|
||||
Err(_) => {
|
||||
return Ok(Some("Action failed".to_string()));
|
||||
return Ok(Some("Auto action failed".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1130,7 +1142,6 @@ impl EventHandler {
|
||||
KeyCode::BackTab => Some(CanvasAction::PrevField),
|
||||
KeyCode::Delete => Some(CanvasAction::DeleteForward),
|
||||
KeyCode::Backspace => Some(CanvasAction::DeleteBackward),
|
||||
// DON'T handle Char(c) in read-only mode - let config handle it
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user