general mode

This commit is contained in:
filipriec
2025-03-23 21:00:53 +01:00
parent 9917195fc4
commit 7caa4d8c3c
2 changed files with 83 additions and 36 deletions

View File

@@ -13,6 +13,7 @@ use crate::modes::{
handlers::{command_mode},
canvas::{edit, read_only, common},
};
use crate::modes::navigation;
use crate::config::binds::key_sequences::KeySequenceTracker;
pub struct EventHandler {
@@ -59,73 +60,51 @@ impl EventHandler {
if let Some(action) = config.get_general_action(key_code, modifiers) {
match action {
"move_up" => {
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
navigation::move_up(app_state);
return Ok((false, String::new()));
}
"move_down" => {
app_state.general.selected_item = app_state.general.selected_item.saturating_add(1);
let item_count = if app_state.ui.show_intro {
2 // Intro options count
} else {
app_state.profile_tree.profiles.len() // Admin panel items
};
navigation::move_down(app_state, item_count);
return Ok((false, String::new()));
}
"next_option" => {
app_state.general.current_option = app_state.general.current_option.saturating_add(1);
navigation::next_option(app_state, 2); // Intro has 2 options
return Ok((false, String::new()));
}
"previous_option" => {
app_state.general.current_option = app_state.general.current_option.saturating_sub(1);
navigation::previous_option(app_state);
return Ok((false, String::new()));
}
"select" => {
if app_state.ui.show_intro {
app_state.ui.show_intro = false;
} else if app_state.ui.show_admin {
app_state.ui.show_admin = false;
}
navigation::select(app_state);
return Ok((false, "Selected".to_string()));
}
"toggle_sidebar" => {
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
navigation::toggle_sidebar(app_state);
return Ok((false, format!("Sidebar {}",
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
)));
}
"next_field" => {
// Increment field navigation
if form_state.fields.len() > 0 {
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
}
navigation::next_field(form_state);
return Ok((false, String::new()));
}
"prev_field" => {
// Decrement field navigation
if form_state.fields.len() > 0 {
form_state.current_field = if form_state.current_field == 0 {
form_state.fields.len() - 1
} else {
form_state.current_field - 1
};
}
navigation::prev_field(form_state);
return Ok((false, String::new()));
}
"enter_command_mode" => {
self.command_mode = true;
self.command_input.clear();
self.command_message.clear();
navigation::handle_enter_command_mode(self);
return Ok((false, String::new()));
}
_ => {}
}
}
if let Some("enter_command_mode") = config.get_action_for_key_in_mode(
&config.keybindings.global,
key_code,
modifiers
) {
self.command_mode = true;
return Ok((false, String::new()));
}
// If no general action matched, return to stay in general mode
return Ok((false, String::new()));
}