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

@@ -80,6 +80,29 @@ pub async fn handle_edit_event(
// Edit-specific actions
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
// --- Special Handling for Tab/Shift+Tab in Role Field ---
if app_state.ui.show_register && register_state.current_field() == 4 {
match action {
"suggestion_up" | "suggestion_down" => { // Mapped to Tab/Shift+Tab
if !register_state.in_suggestion_mode {
// Enter suggestion mode
register_state.update_role_suggestions(); // Populate suggestions
if !register_state.role_suggestions.is_empty() {
register_state.in_suggestion_mode = true;
register_state.show_role_suggestions = true;
register_state.selected_suggestion_index = Some(0); // Select first
return Ok("Suggestions shown".to_string()); // Consume the event
} else {
return Ok("No suggestions available".to_string()); // Consume, do nothing else
}
}
// If already in suggestion mode, fall through to execute the action via auth_e
}
_ => {} // Other actions fall through
}
}
// --- End Special Handling ---
return if app_state.ui.show_login {
auth_e::execute_edit_action(
action,
@@ -115,6 +138,12 @@ pub async fn handle_edit_event(
// Character insertion
if let KeyCode::Char(_) = key.code {
// If in suggestion mode, exit it before inserting char
if app_state.ui.show_register && register_state.in_suggestion_mode {
register_state.in_suggestion_mode = false;
register_state.show_role_suggestions = false;
register_state.selected_suggestion_index = None;
}
let is_role_field = app_state.ui.show_register && register_state.current_field() == 4;
// --- End Autocomplete Trigger ---
@@ -149,15 +178,16 @@ pub async fn handle_edit_event(
total_count
).await
};
// After character insertion/deletion, update suggestions if it was the role field
if is_role_field {
register_state.update_role_suggestions();
}
}
// Handle Backspace/Delete for Autocomplete Trigger
if matches!(key.code, KeyCode::Backspace | KeyCode::Delete) {
// If in suggestion mode, exit it before deleting char
if app_state.ui.show_register && register_state.in_suggestion_mode {
register_state.in_suggestion_mode = false;
register_state.show_role_suggestions = false;
register_state.selected_suggestion_index = None;
}
let is_role_field = app_state.ui.show_register && register_state.current_field() == 4;
let action_str = if key.code == KeyCode::Backspace { "backspace" } else { "delete_char" };
@@ -177,9 +207,6 @@ pub async fn handle_edit_event(
Ok("Action not applicable here".to_string()) // Placeholder
}?;
if is_role_field {
register_state.update_role_suggestions();
}
return Ok(result);
}