moved to auth_e functions for dropdown from edit mode file
This commit is contained in:
@@ -80,95 +80,6 @@ pub async fn handle_edit_event(
|
||||
|
||||
// Edit-specific actions
|
||||
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
|
||||
// --- Autocomplete Dropdown Interaction Handling (PRIORITY) ---
|
||||
if app_state.ui.show_register && register_state.current_field() == 4 && register_state.show_role_suggestions {
|
||||
match action {
|
||||
"suggestion_down" => {
|
||||
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 });
|
||||
return Ok("Suggestion changed".to_string());
|
||||
}
|
||||
"suggestion_up" => {
|
||||
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 == 0 { max_index } else { current_index.saturating_sub(1) });
|
||||
return Ok("Suggestion changed".to_string());
|
||||
}
|
||||
"select_suggestion" => {
|
||||
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();
|
||||
// Hide dropdown after selection
|
||||
register_state.show_role_suggestions = false;
|
||||
register_state.selected_suggestion_index = None;
|
||||
register_state.role_suggestions.clear();
|
||||
// Move cursor to end of selected role
|
||||
let new_cursor_pos = register_state.role.len();
|
||||
register_state.set_current_cursor_pos(new_cursor_pos);
|
||||
*ideal_cursor_column = new_cursor_pos;
|
||||
return Ok(format!("Selected role: {}", register_state.role));
|
||||
}
|
||||
}
|
||||
return Ok("No suggestion selected".to_string());
|
||||
}
|
||||
"hide_suggestions" => {
|
||||
register_state.show_role_suggestions = false;
|
||||
register_state.selected_suggestion_index = None;
|
||||
return Ok("Suggestions hidden".to_string());
|
||||
}
|
||||
// Allow field navigation to hide suggestions
|
||||
"next_field" | "prev_field" => {
|
||||
register_state.show_role_suggestions = false;
|
||||
register_state.selected_suggestion_index = None;
|
||||
// Fall through to execute the navigation action below
|
||||
}
|
||||
_ => {} // Other edit actions might be ignored while dropdown is active
|
||||
}
|
||||
}
|
||||
// --- End Autocomplete Interaction Handling ---
|
||||
|
||||
|
||||
// --- Autocomplete Handling for Role Field ---
|
||||
if app_state.ui.show_register && register_state.current_field() == 4 {
|
||||
match action {
|
||||
"suggestion_down" if register_state.show_role_suggestions => {
|
||||
let max_index = register_state.role_suggestions.len() - 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 });
|
||||
return Ok("Suggestion changed".to_string());
|
||||
}
|
||||
"suggestion_up" if register_state.show_role_suggestions => {
|
||||
let max_index = register_state.role_suggestions.len() - 1;
|
||||
let current_index = register_state.selected_suggestion_index.unwrap_or(0);
|
||||
register_state.selected_suggestion_index = Some(if current_index == 0 { max_index } else { current_index - 1 });
|
||||
return Ok("Suggestion changed".to_string());
|
||||
}
|
||||
"select_suggestion" if register_state.show_role_suggestions => {
|
||||
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();
|
||||
register_state.show_role_suggestions = false;
|
||||
register_state.selected_suggestion_index = None;
|
||||
register_state.role_suggestions.clear();
|
||||
// Optionally move to next field or exit edit mode here
|
||||
return Ok(format!("Selected role: {}", register_state.role));
|
||||
}
|
||||
}
|
||||
return Ok("No suggestion selected".to_string());
|
||||
}
|
||||
"hide_suggestions" => {
|
||||
register_state.show_role_suggestions = false;
|
||||
register_state.selected_suggestion_index = None;
|
||||
return Ok("Suggestions hidden".to_string());
|
||||
}
|
||||
// Let other edit actions (like move_*) fall through for the role field if desired
|
||||
// Or explicitly handle them here if they should behave differently
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
// --- End Autocomplete Handling ---
|
||||
|
||||
return if app_state.ui.show_login {
|
||||
auth_e::execute_edit_action(
|
||||
action,
|
||||
|
||||
Reference in New Issue
Block a user