compiled and working sidebar in ratatui
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// src/modes/handlers/event.rs
|
||||
|
||||
use crossterm::event::Event;
|
||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
||||
use crossterm::cursor::SetCursorStyle;
|
||||
use crate::tui::terminal::{
|
||||
core::TerminalCore,
|
||||
@@ -9,6 +9,8 @@ use crate::tui::terminal::{
|
||||
};
|
||||
use crate::config::config::Config;
|
||||
use crate::ui::handlers::form::FormState;
|
||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||
use crate::state::state::AppState;
|
||||
use crate::modes::handlers::{edit, command_mode, read_only};
|
||||
use crate::config::key_sequences::KeySequenceTracker;
|
||||
use super::common;
|
||||
@@ -44,22 +46,36 @@ impl EventHandler {
|
||||
grpc_client: &mut GrpcClient,
|
||||
command_handler: &mut CommandHandler,
|
||||
form_state: &mut FormState,
|
||||
is_saved: &mut bool,
|
||||
app_state: &mut crate::state::state::AppState,
|
||||
total_count: u64,
|
||||
current_position: &mut u64,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
if let Event::Key(key) = event {
|
||||
let key_code = key.code;
|
||||
let modifiers = key.modifiers;
|
||||
|
||||
if UiStateHandler::toggle_sidebar(
|
||||
&mut app_state.ui,
|
||||
config,
|
||||
key_code,
|
||||
modifiers,
|
||||
) {
|
||||
return Ok((false, format!("Sidebar {}",
|
||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||
)));
|
||||
}
|
||||
|
||||
if let Some(action) = config.get_action_for_key_in_mode(
|
||||
&config.keybindings.common,
|
||||
key.code,
|
||||
key.modifiers
|
||||
key_code,
|
||||
modifiers
|
||||
) {
|
||||
match action {
|
||||
"save" => {
|
||||
let message = common::save(
|
||||
form_state,
|
||||
grpc_client,
|
||||
is_saved,
|
||||
&mut app_state.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
@@ -94,7 +110,7 @@ impl EventHandler {
|
||||
&mut self.command_input,
|
||||
&mut self.command_message,
|
||||
grpc_client,
|
||||
is_saved,
|
||||
&mut app_state.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
@@ -107,7 +123,7 @@ impl EventHandler {
|
||||
}
|
||||
|
||||
if self.is_edit_mode {
|
||||
if config.is_exit_edit_mode(key.code, key.modifiers) {
|
||||
if config.is_exit_edit_mode(key_code, modifiers) {
|
||||
if form_state.has_unsaved_changes {
|
||||
self.command_message = "Unsaved changes! Use :w to save or :q! to discard".to_string();
|
||||
return Ok((false, self.command_message.clone()));
|
||||
@@ -131,7 +147,7 @@ impl EventHandler {
|
||||
form_state,
|
||||
&mut self.ideal_cursor_column,
|
||||
&mut self.command_message,
|
||||
is_saved,
|
||||
&mut app_state.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
grpc_client,
|
||||
@@ -140,7 +156,7 @@ impl EventHandler {
|
||||
self.key_sequence_tracker.reset();
|
||||
return Ok((false, result));
|
||||
} else {
|
||||
if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) {
|
||||
if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) {
|
||||
if action == "enter_command_mode" {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
@@ -149,7 +165,7 @@ impl EventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if config.is_enter_edit_mode_before(key.code, key.modifiers) {
|
||||
if config.is_enter_edit_mode_before(key_code, modifiers) {
|
||||
self.is_edit_mode = true;
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Edit mode".to_string();
|
||||
@@ -157,7 +173,7 @@ impl EventHandler {
|
||||
return Ok((false, self.command_message.clone()));
|
||||
}
|
||||
|
||||
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
|
||||
if config.is_enter_edit_mode_after(key_code, modifiers) {
|
||||
let current_input = form_state.get_current_input();
|
||||
if !current_input.is_empty() && form_state.current_cursor_pos < current_input.len() {
|
||||
form_state.current_cursor_pos += 1;
|
||||
|
||||
Reference in New Issue
Block a user