dialog movement fixed
This commit is contained in:
@@ -17,7 +17,7 @@ use crate::tui::functions::{intro, admin};
|
||||
use crate::modes::{
|
||||
common::command_mode,
|
||||
canvas::{edit, read_only, common_mode},
|
||||
general::navigation,
|
||||
general::{navigation, dialog},
|
||||
};
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
use crate::modes::handlers::mode_manager::{ModeManager, AppMode};
|
||||
@@ -72,58 +72,12 @@ impl EventHandler {
|
||||
let current_mode = ModeManager::derive_mode(app_state, self);
|
||||
app_state.update_mode(current_mode);
|
||||
|
||||
// --- DIALOG MODALITY CHECK ---
|
||||
// --- DIALOG MODALITY ---
|
||||
// If a dialog is showing, intercept and handle ONLY dialog inputs.
|
||||
if app_state.ui.dialog.dialog_show {
|
||||
if let Event::Key(key) = event {
|
||||
// Always allow Esc to dismiss
|
||||
if key.code == KeyCode::Esc {
|
||||
app_state.hide_dialog();
|
||||
return Ok(EventOutcome::Ok("Dialog dismissed".to_string()));
|
||||
}
|
||||
|
||||
// Check general bindings for dialog actions
|
||||
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
||||
match action {
|
||||
"move_down" | "move_right" => {
|
||||
let current_index = app_state.ui.dialog.dialog_active_button_index;
|
||||
let num_buttons = app_state.ui.dialog.dialog_buttons.len();
|
||||
if num_buttons > 0 && current_index < num_buttons - 1 {
|
||||
app_state.ui.dialog.dialog_active_button_index += 1;
|
||||
}
|
||||
return Ok(EventOutcome::Ok(String::new())); // Consume event
|
||||
}
|
||||
"move_up" | "move_left" => {
|
||||
let current_index = app_state.ui.dialog.dialog_active_button_index;
|
||||
if current_index > 0 {
|
||||
app_state.ui.dialog.dialog_active_button_index -= 1;
|
||||
}
|
||||
return Ok(EventOutcome::Ok(String::new())); // Consume event
|
||||
}
|
||||
"select" => {
|
||||
let selected_index = app_state.ui.dialog.dialog_active_button_index;
|
||||
let selected_label = app_state.get_active_dialog_button_label().unwrap_or("").to_string();
|
||||
let mut message = format!("Dialog '{}' selected", selected_label);
|
||||
|
||||
// --- Add specific actions based on button index or label ---
|
||||
if selected_label.eq_ignore_ascii_case("menu") {
|
||||
app_state.ui.show_login = false;
|
||||
app_state.ui.show_intro = true;
|
||||
// focus_outside_canvas is handled by hide_dialog
|
||||
message = "Returning to menu".to_string();
|
||||
} else if selected_label.eq_ignore_ascii_case("exit") {
|
||||
app_state.hide_dialog();
|
||||
return Ok(EventOutcome::Exit("Exiting via dialog".to_string()));
|
||||
}
|
||||
// --- End specific actions ---
|
||||
app_state.hide_dialog(); // Hide dialog after processing selection
|
||||
return Ok(EventOutcome::Ok(message)); // Consume event
|
||||
}
|
||||
_ => {} // Ignore other general actions when dialog is shown
|
||||
}
|
||||
}
|
||||
}
|
||||
// If dialog is shown, consume any event not handled above
|
||||
if let Some(dialog_result) = dialog::handle_dialog_event(&event, config, app_state).await {
|
||||
return dialog_result;
|
||||
}
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
// --- END DIALOG MODALITY CHECK ---
|
||||
|
||||
Reference in New Issue
Block a user