working common mode

This commit is contained in:
filipriec
2025-02-28 23:15:30 +01:00
parent f2d2943232
commit f1d2e5c43d
6 changed files with 205 additions and 107 deletions

View File

@@ -7,6 +7,7 @@ use crate::config::config::Config;
use crate::ui::handlers::form::FormState;
use crate::modes::handlers::{edit, command_mode, read_only};
use crate::config::key_sequences::KeySequenceTracker;
use super::common;
pub struct EventHandler {
pub command_mode: bool,
@@ -42,6 +43,39 @@ impl EventHandler {
current_position: &mut u64,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
if let Event::Key(key) = event {
if let Some(action) = config.get_action_for_key_in_mode(
&config.keybindings.common,
key.code,
key.modifiers
) {
match action {
"save" => {
let message = common::save(
form_state,
app_terminal,
is_saved,
current_position,
total_count,
).await?;
return Ok((false, message));
},
"force_quit" => {
let (should_exit, message) = common::force_quit();
return Ok((should_exit, message));
},
"save_and_quit" => {
let (should_exit, message) = common::save_and_quit(
form_state,
app_terminal,
current_position,
total_count,
).await?;
return Ok((should_exit, message));
},
_ => {}
}
}
// Handle command mode with highest priority
if self.command_mode {
let (should_exit, message, exit_command_mode) = command_mode::handle_command_event(
@@ -98,6 +132,10 @@ impl EventHandler {
form_state,
&mut self.ideal_cursor_column,
&mut self.command_message,
app_terminal,
is_saved,
current_position,
total_count,
).await?;
self.key_sequence_tracker.reset();