edit to read_only mode without save
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
// src/modes/handlers/event.rs
|
// src/modes/handlers/event.rs
|
||||||
use crossterm::event::Event;
|
use crossterm::event::Event;
|
||||||
use crossterm::cursor::SetCursorStyle;
|
use crossterm::cursor::SetCursorStyle;
|
||||||
use crate::tui::terminal::{
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
core::TerminalCore,
|
|
||||||
};
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
use crate::modes::common::commands::CommandHandler;
|
use crate::modes::common::commands::CommandHandler;
|
||||||
@@ -13,7 +11,7 @@ use crate::state::pages::auth::AuthState;
|
|||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
common::{command_mode},
|
common::command_mode,
|
||||||
canvas::{edit, read_only, common_mode},
|
canvas::{edit, read_only, common_mode},
|
||||||
general::navigation,
|
general::navigation,
|
||||||
};
|
};
|
||||||
@@ -28,7 +26,6 @@ pub struct EventHandler {
|
|||||||
pub edit_mode_cooldown: bool,
|
pub edit_mode_cooldown: bool,
|
||||||
pub ideal_cursor_column: usize,
|
pub ideal_cursor_column: usize,
|
||||||
pub key_sequence_tracker: KeySequenceTracker,
|
pub key_sequence_tracker: KeySequenceTracker,
|
||||||
// pub auth_state: AuthState, // Removed
|
|
||||||
pub auth_client: AuthClient,
|
pub auth_client: AuthClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +39,6 @@ impl EventHandler {
|
|||||||
edit_mode_cooldown: false,
|
edit_mode_cooldown: false,
|
||||||
ideal_cursor_column: 0,
|
ideal_cursor_column: 0,
|
||||||
key_sequence_tracker: KeySequenceTracker::new(800),
|
key_sequence_tracker: KeySequenceTracker::new(800),
|
||||||
// auth_state: AuthState::new(), // Removed
|
|
||||||
auth_client: AuthClient::new().await?,
|
auth_client: AuthClient::new().await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -55,12 +51,11 @@ impl EventHandler {
|
|||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
command_handler: &mut CommandHandler,
|
command_handler: &mut CommandHandler,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
auth_state: &mut AuthState, // Added
|
auth_state: &mut AuthState,
|
||||||
app_state: &mut crate::state::state::AppState,
|
app_state: &mut crate::state::state::AppState,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
// Determine current mode based on app state and event handler state
|
|
||||||
let current_mode = ModeManager::derive_mode(app_state, self);
|
let current_mode = ModeManager::derive_mode(app_state, self);
|
||||||
app_state.update_mode(current_mode);
|
app_state.update_mode(current_mode);
|
||||||
|
|
||||||
@@ -68,14 +63,12 @@ impl EventHandler {
|
|||||||
let key_code = key.code;
|
let key_code = key.code;
|
||||||
let modifiers = key.modifiers;
|
let modifiers = key.modifiers;
|
||||||
|
|
||||||
// Handle common actions across all modes
|
|
||||||
if UiStateHandler::toggle_sidebar(&mut app_state.ui, config, key_code, modifiers) {
|
if UiStateHandler::toggle_sidebar(&mut app_state.ui, config, key_code, modifiers) {
|
||||||
return Ok((false, format!("Sidebar {}",
|
return Ok((false, format!("Sidebar {}",
|
||||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mode-specific handling
|
|
||||||
match current_mode {
|
match current_mode {
|
||||||
AppMode::General => {
|
AppMode::General => {
|
||||||
return navigation::handle_navigation_event(
|
return navigation::handle_navigation_event(
|
||||||
@@ -90,7 +83,6 @@ impl EventHandler {
|
|||||||
},
|
},
|
||||||
|
|
||||||
AppMode::ReadOnly => {
|
AppMode::ReadOnly => {
|
||||||
// Check for mode transitions first
|
|
||||||
if config.is_enter_edit_mode_before(key_code, modifiers) &&
|
if config.is_enter_edit_mode_before(key_code, modifiers) &&
|
||||||
ModeManager::can_enter_edit_mode(current_mode) {
|
ModeManager::can_enter_edit_mode(current_mode) {
|
||||||
self.is_edit_mode = true;
|
self.is_edit_mode = true;
|
||||||
@@ -129,7 +121,6 @@ impl EventHandler {
|
|||||||
return Ok((false, self.command_message.clone()));
|
return Ok((false, self.command_message.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for entering command mode
|
|
||||||
if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) {
|
if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) {
|
||||||
if action == "enter_command_mode" && ModeManager::can_enter_command_mode(current_mode) {
|
if action == "enter_command_mode" && ModeManager::can_enter_command_mode(current_mode) {
|
||||||
self.command_mode = true;
|
self.command_mode = true;
|
||||||
@@ -139,7 +130,6 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for core application actions (save, quit, etc.)
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
if let Some(action) = config.get_action_for_key_in_mode(
|
||||||
&config.keybindings.common,
|
&config.keybindings.common,
|
||||||
key_code,
|
key_code,
|
||||||
@@ -150,7 +140,7 @@ impl EventHandler {
|
|||||||
return common_mode::handle_core_action(
|
return common_mode::handle_core_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state, // Changed
|
auth_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut self.auth_client,
|
&mut self.auth_client,
|
||||||
terminal,
|
terminal,
|
||||||
@@ -163,13 +153,12 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let read_only mode handle its own actions
|
|
||||||
return read_only::handle_read_only_event(
|
return read_only::handle_read_only_event(
|
||||||
&app_state,
|
&app_state,
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state, // Changed
|
auth_state,
|
||||||
&mut self.key_sequence_tracker,
|
&mut self.key_sequence_tracker,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
@@ -181,21 +170,22 @@ impl EventHandler {
|
|||||||
},
|
},
|
||||||
|
|
||||||
AppMode::Edit => {
|
AppMode::Edit => {
|
||||||
// Check for exiting edit mode
|
|
||||||
if config.is_exit_edit_mode(key_code, modifiers) {
|
if config.is_exit_edit_mode(key_code, modifiers) {
|
||||||
|
self.is_edit_mode = false;
|
||||||
|
self.edit_mode_cooldown = true;
|
||||||
|
|
||||||
let has_changes = if app_state.ui.show_login {
|
let has_changes = if app_state.ui.show_login {
|
||||||
auth_state.has_unsaved_changes()
|
auth_state.has_unsaved_changes()
|
||||||
} else {
|
} else {
|
||||||
form_state.has_unsaved_changes()
|
form_state.has_unsaved_changes()
|
||||||
};
|
};
|
||||||
|
|
||||||
if has_changes {
|
self.command_message = if has_changes {
|
||||||
self.command_message = "Unsaved changes! Use :w to save or :q! to discard".to_string();
|
"Exited edit mode (unsaved changes remain)".to_string()
|
||||||
return Ok((false, self.command_message.clone()));
|
} else {
|
||||||
}
|
"Read-only mode".to_string()
|
||||||
self.is_edit_mode = false;
|
};
|
||||||
self.edit_mode_cooldown = true;
|
|
||||||
self.command_message = "Read-only mode".to_string();
|
|
||||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
||||||
|
|
||||||
let current_input = if app_state.ui.show_login {
|
let current_input = if app_state.ui.show_login {
|
||||||
@@ -222,7 +212,6 @@ impl EventHandler {
|
|||||||
return Ok((false, self.command_message.clone()));
|
return Ok((false, self.command_message.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for core application actions (save, quit, etc.)
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
if let Some(action) = config.get_action_for_key_in_mode(
|
||||||
&config.keybindings.common,
|
&config.keybindings.common,
|
||||||
key_code,
|
key_code,
|
||||||
@@ -230,29 +219,28 @@ impl EventHandler {
|
|||||||
) {
|
) {
|
||||||
match action {
|
match action {
|
||||||
"save" | "force_quit" | "save_and_quit" | "revert" => {
|
"save" | "force_quit" | "save_and_quit" | "revert" => {
|
||||||
return common_mode::handle_core_action(
|
return common_mode::handle_core_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state, // Changed
|
auth_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut self.auth_client,
|
&mut self.auth_client,
|
||||||
terminal,
|
terminal,
|
||||||
app_state,
|
app_state,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
).await;
|
).await;
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let edit mode handle its own actions
|
|
||||||
let result = edit::handle_edit_event(
|
let result = edit::handle_edit_event(
|
||||||
app_state.ui.show_login,
|
app_state.ui.show_login,
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state, // Changed
|
auth_state,
|
||||||
&mut self.ideal_cursor_column,
|
&mut self.ideal_cursor_column,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
&mut app_state.ui.is_saved,
|
&mut app_state.ui.is_saved,
|
||||||
@@ -288,9 +276,7 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-key events or if no specific handler was matched
|
|
||||||
self.edit_mode_cooldown = false;
|
self.edit_mode_cooldown = false;
|
||||||
Ok((false, self.command_message.clone()))
|
Ok((false, self.command_message.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user