suggestions on tab, still not working yet

This commit is contained in:
filipriec
2025-04-12 15:31:29 +02:00
parent 6d6df7ca5c
commit 50a329fc0d
5 changed files with 67 additions and 34 deletions

View File

@@ -299,13 +299,13 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
}
// --- Autocomplete Actions ---
"suggestion_down" | "suggestion_up" | "select_suggestion" | "hide_suggestions" => {
"suggestion_down" | "suggestion_up" | "select_suggestion" | "exit_suggestion_mode" => {
// Attempt to downcast to RegisterState
if let Some(register_state) = (state as &mut dyn Any).downcast_mut::<RegisterState>() {
// Only handle if it's the role field (index 4) and suggestions are shown (except for hide)
if register_state.current_field() == 4 {
match action {
"suggestion_down" if register_state.show_role_suggestions => {
"suggestion_down" if register_state.in_suggestion_mode => {
let max_index = register_state.role_suggestions.len().saturating_sub(1);
let current_index = register_state.selected_suggestion_index.unwrap_or(0);
register_state.selected_suggestion_index = Some(if current_index >= max_index { 0 } else { current_index + 1 });
@@ -317,7 +317,7 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
register_state.selected_suggestion_index = Some(if current_index == 0 { max_index } else { current_index.saturating_sub(1) });
Ok("Suggestion changed up".to_string())
}
"select_suggestion" if register_state.show_role_suggestions => {
"select_suggestion" if register_state.in_suggestion_mode => {
if let Some(selected_index) = register_state.selected_suggestion_index {
if let Some(selected_role) = register_state.role_suggestions.get(selected_index) {
register_state.role = selected_role.clone();
@@ -335,9 +335,10 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
Ok("No suggestion selected".to_string())
}
}
"hide_suggestions" => {
"exit_suggestion_mode" => { // Handle Esc
register_state.show_role_suggestions = false;
register_state.selected_suggestion_index = None;
register_state.in_suggestion_mode = false;
Ok("Suggestions hidden".to_string())
}
_ => Ok("".to_string()) // Action doesn't apply in this state (e.g., suggestions not shown)