attempt for dropdown generalization, minor change really
This commit is contained in:
@@ -300,9 +300,9 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
|
|||||||
|
|
||||||
// --- Autocomplete Actions ---
|
// --- Autocomplete Actions ---
|
||||||
"suggestion_down" | "suggestion_up" | "select_suggestion" | "exit_suggestion_mode" => {
|
"suggestion_down" | "suggestion_up" | "select_suggestion" | "exit_suggestion_mode" => {
|
||||||
// Attempt to downcast to RegisterState
|
// Attempt to downcast to RegisterState to handle suggestion logic here
|
||||||
if let Some(register_state) = (state as &mut dyn Any).downcast_mut::<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)
|
// Only handle if it's the role field (index 4)
|
||||||
if register_state.current_field() == 4 {
|
if register_state.current_field() == 4 {
|
||||||
match action {
|
match action {
|
||||||
"suggestion_down" if register_state.in_suggestion_mode => {
|
"suggestion_down" if register_state.in_suggestion_mode => {
|
||||||
@@ -319,34 +319,37 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
|
|||||||
}
|
}
|
||||||
"select_suggestion" if register_state.in_suggestion_mode => {
|
"select_suggestion" if register_state.in_suggestion_mode => {
|
||||||
if let Some(index) = register_state.selected_suggestion_index {
|
if let Some(index) = register_state.selected_suggestion_index {
|
||||||
let selected_role = register_state.role_suggestions[index].clone();
|
if let Some(selected_role) = register_state.role_suggestions.get(index).cloned() {
|
||||||
register_state.role = selected_role.clone(); // Update the role field
|
register_state.role = selected_role.clone(); // Update the role field
|
||||||
register_state.in_suggestion_mode = false; // Exit suggestion mode
|
register_state.in_suggestion_mode = false; // Exit suggestion mode
|
||||||
register_state.show_role_suggestions = false; // Hide suggestions
|
register_state.show_role_suggestions = false; // Hide suggestions
|
||||||
register_state.selected_suggestion_index = None; // Clear selection
|
register_state.selected_suggestion_index = None; // Clear selection
|
||||||
Ok(format!("Selected role: {}", selected_role)) // Return success message
|
Ok(format!("Selected role: {}", selected_role)) // Return success message
|
||||||
|
} else {
|
||||||
|
Ok("Selected suggestion index out of bounds.".to_string()) // Error case
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok("No suggestion selected".to_string())
|
Ok("No suggestion selected".to_string())
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"exit_suggestion_mode" => { // Handle Esc
|
"exit_suggestion_mode" => { // Handle Esc or other conditions
|
||||||
register_state.show_role_suggestions = false;
|
register_state.show_role_suggestions = false;
|
||||||
register_state.selected_suggestion_index = None;
|
register_state.selected_suggestion_index = None;
|
||||||
register_state.in_suggestion_mode = false;
|
register_state.in_suggestion_mode = false;
|
||||||
Ok("Suggestions hidden".to_string())
|
Ok("Suggestions hidden".to_string())
|
||||||
}
|
}
|
||||||
"suggestion_down" | "suggestion_up" | "select_suggestion" => {
|
_ => {
|
||||||
Ok("Suggestion action ignored: Not in suggestion mode.".to_string())
|
// Action is suggestion-related but state doesn't match (e.g., not in suggestion mode)
|
||||||
|
Ok("Suggestion action ignored: State mismatch.".to_string())
|
||||||
}
|
}
|
||||||
_ => Ok("".to_string())
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok("".to_string())
|
// It's RegisterState, but not the role field
|
||||||
}
|
Ok("Suggestion action ignored: Not on role field.".to_string())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Downcast failed - this action is only for RegisterState
|
// Downcast failed - this action is only for RegisterState
|
||||||
Ok(format!("Action '{}' not applicable for this form type.", action))
|
Ok(format!("Action '{}' not applicable for this state type.", action))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// --- End Autocomplete Actions ---
|
// --- End Autocomplete Actions ---
|
||||||
|
|||||||
Reference in New Issue
Block a user