finally works as i wanted it to
This commit is contained in:
@@ -33,6 +33,54 @@ pub async fn handle_edit_event(
|
||||
grpc_client: &mut GrpcClient,
|
||||
app_state: &AppState,
|
||||
) -> Result<EditEventOutcome> {
|
||||
if app_state.ui.show_form && form_state.autocomplete_active {
|
||||
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
|
||||
match action {
|
||||
"suggestion_down" => {
|
||||
if !form_state.autocomplete_suggestions.is_empty() {
|
||||
let current = form_state.selected_suggestion_index.unwrap_or(0);
|
||||
let next = (current + 1) % form_state.autocomplete_suggestions.len();
|
||||
form_state.selected_suggestion_index = Some(next);
|
||||
}
|
||||
return Ok(EditEventOutcome::Message(String::new()));
|
||||
}
|
||||
"suggestion_up" => {
|
||||
if !form_state.autocomplete_suggestions.is_empty() {
|
||||
let current = form_state.selected_suggestion_index.unwrap_or(0);
|
||||
let prev = if current == 0 {
|
||||
form_state.autocomplete_suggestions.len() - 1
|
||||
} else {
|
||||
current - 1
|
||||
};
|
||||
form_state.selected_suggestion_index = Some(prev);
|
||||
}
|
||||
return Ok(EditEventOutcome::Message(String::new()));
|
||||
}
|
||||
"exit" => {
|
||||
form_state.deactivate_autocomplete();
|
||||
return Ok(EditEventOutcome::Message("Autocomplete cancelled".to_string()));
|
||||
}
|
||||
"enter_decider" => {
|
||||
if let Some(selected_idx) = form_state.selected_suggestion_index {
|
||||
if let Some(selection) = form_state.autocomplete_suggestions.get(selected_idx).cloned() {
|
||||
let current_input = form_state.get_current_input_mut();
|
||||
*current_input = selection;
|
||||
let new_cursor_pos = current_input.len();
|
||||
form_state.set_current_cursor_pos(new_cursor_pos);
|
||||
*ideal_cursor_column = new_cursor_pos;
|
||||
form_state.deactivate_autocomplete();
|
||||
form_state.set_has_unsaved_changes(true);
|
||||
return Ok(EditEventOutcome::Message("Selection made".to_string()));
|
||||
}
|
||||
}
|
||||
// If no selection, fall through to default behavior
|
||||
form_state.deactivate_autocomplete();
|
||||
}
|
||||
_ => {} // Other keys are not special, let them fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some("enter_command_mode") = config.get_action_for_key_in_mode(
|
||||
&config.keybindings.global,
|
||||
key.code,
|
||||
|
||||
Reference in New Issue
Block a user