trigger dropdown, not working at all, needs proper implementation, ready for debug

This commit is contained in:
filipriec
2025-04-11 15:40:50 +02:00
parent cf1aa4fd2a
commit a7389db674
7 changed files with 260 additions and 26 deletions

View File

@@ -3,6 +3,7 @@
use crate::config::binds::config::Config;
use crate::services::grpc_client::GrpcClient;
use crate::state::pages::{auth::{AuthState, RegisterState}};
use crate::state::canvas_state::CanvasState;
use crate::state::pages::form::FormState;
use crate::functions::modes::edit::{auth_e, form_e};
use crate::modes::handlers::event::EventOutcome;
@@ -79,6 +80,46 @@ pub async fn handle_edit_event(
// Edit-specific actions
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
// --- 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,
@@ -114,6 +155,11 @@ pub async fn handle_edit_event(
// Character insertion
if let KeyCode::Char(_) = key.code {
// --- Autocomplete Trigger on Char Insert ---
let is_role_field = app_state.ui.show_register && register_state.current_field() == 4;
let result = // Store result before potential update
// --- End Autocomplete Trigger ---
return if app_state.ui.show_login {
auth_e::execute_edit_action(
"insert_char",
@@ -145,6 +191,39 @@ 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();
}
return result; // Return the result from execute_edit_action
}
// Handle Backspace/Delete for Autocomplete Trigger
if matches!(key.code, KeyCode::Backspace | KeyCode::Delete) {
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" };
// Execute the action first
let result = if app_state.ui.show_register {
auth_e::execute_edit_action(
action_str,
key,
register_state,
ideal_cursor_column,
grpc_client,
current_position,
total_count
).await
} else {
// Handle for login/form if needed, assuming auth_e covers RegisterState
Ok("Action not applicable here".to_string()) // Placeholder
}?;
if is_role_field {
register_state.update_role_suggestions();
}
return Ok(result);
}
Ok(command_message.clone())