HIGHLIGHT MODE
This commit is contained in:
@@ -35,6 +35,7 @@ use crate::modes::{
|
||||
common::{command_mode, commands::CommandHandler},
|
||||
handlers::mode_manager::{ModeManager, AppMode},
|
||||
canvas::{edit, read_only, common_mode},
|
||||
highlight::highlight,
|
||||
general::{navigation, dialog},
|
||||
};
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
@@ -52,6 +53,8 @@ pub struct EventHandler {
|
||||
pub command_input: String,
|
||||
pub command_message: String,
|
||||
pub is_edit_mode: bool,
|
||||
pub is_highlight_mode: bool,
|
||||
pub highlight_anchor: Option<(usize, usize)>,
|
||||
pub edit_mode_cooldown: bool,
|
||||
pub ideal_cursor_column: usize,
|
||||
pub key_sequence_tracker: KeySequenceTracker,
|
||||
@@ -65,6 +68,8 @@ impl EventHandler {
|
||||
command_input: String::new(),
|
||||
command_message: String::new(),
|
||||
is_edit_mode: false,
|
||||
is_highlight_mode: false,
|
||||
highlight_anchor: None,
|
||||
edit_mode_cooldown: false,
|
||||
ideal_cursor_column: 0,
|
||||
key_sequence_tracker: KeySequenceTracker::new(800),
|
||||
@@ -93,7 +98,6 @@ impl EventHandler {
|
||||
let current_mode = ModeManager::derive_mode(app_state, self);
|
||||
app_state.update_mode(current_mode);
|
||||
|
||||
// Determine the current view, including dynamic names
|
||||
let current_view = {
|
||||
let ui = &app_state.ui;
|
||||
if ui.show_intro { AppView::Intro }
|
||||
@@ -108,7 +112,6 @@ impl EventHandler {
|
||||
};
|
||||
buffer_state.update_history(current_view);
|
||||
|
||||
// --- DIALOG MODALITY ---
|
||||
if app_state.ui.dialog.dialog_show {
|
||||
if let Some(dialog_result) = dialog::handle_dialog_event(
|
||||
&event, config, app_state, auth_state, login_state, register_state, buffer_state
|
||||
@@ -117,7 +120,6 @@ impl EventHandler {
|
||||
}
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
// --- END DIALOG MODALITY CHECK ---
|
||||
|
||||
if let Event::Key(key) = event {
|
||||
let key_code = key.code;
|
||||
@@ -135,10 +137,10 @@ impl EventHandler {
|
||||
);
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
}
|
||||
// --- Buffer Switching (Check Global) ---
|
||||
|
||||
if !matches!(current_mode, AppMode::Edit | AppMode::Command) {
|
||||
if let Some(action) = config.get_action_for_key_in_mode(
|
||||
&config.keybindings.global, key_code, modifiers // Check global bindings
|
||||
&config.keybindings.global, key_code, modifiers
|
||||
) {
|
||||
match action {
|
||||
"next_buffer" => {
|
||||
@@ -151,11 +153,10 @@ impl EventHandler {
|
||||
return Ok(EventOutcome::Ok("Switched to previous buffer".to_string()));
|
||||
}
|
||||
}
|
||||
_ => {} // Other global actions could be handled here if needed
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- End Global UI Toggles ---
|
||||
|
||||
match current_mode {
|
||||
AppMode::General => {
|
||||
@@ -174,7 +175,7 @@ impl EventHandler {
|
||||
).await;
|
||||
match nav_outcome {
|
||||
Ok(EventOutcome::ButtonSelected { context, index }) => {
|
||||
let mut message = String::from("Selected"); // Default message
|
||||
let mut message = String::from("Selected");
|
||||
match context {
|
||||
UiContext::Intro => {
|
||||
intro::handle_intro_selection(app_state, buffer_state, index);
|
||||
@@ -202,22 +203,35 @@ impl EventHandler {
|
||||
}
|
||||
UiContext::Admin => {
|
||||
admin::handle_admin_selection(app_state, admin_state);
|
||||
|
||||
message = format!("Admin Option {} selected", index);
|
||||
}
|
||||
UiContext::Dialog => {
|
||||
message = "Internal error: Unexpected dialog state".to_string();
|
||||
}
|
||||
}
|
||||
return Ok(EventOutcome::Ok(message)); // Return Ok with message
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
}
|
||||
other => return other, // Pass through Ok, Err, DataSaved directly
|
||||
other => return other,
|
||||
}
|
||||
},
|
||||
|
||||
AppMode::ReadOnly => {
|
||||
if config.is_enter_edit_mode_before(key_code, modifiers) &&
|
||||
ModeManager::can_enter_edit_mode(current_mode) {
|
||||
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_highlight_mode")
|
||||
&& ModeManager::can_enter_highlight_mode(current_mode) {
|
||||
self.is_highlight_mode = true;
|
||||
let current_field_index = if app_state.ui.show_login { login_state.current_field() }
|
||||
else if app_state.ui.show_register { register_state.current_field() }
|
||||
else { form_state.current_field() };
|
||||
let current_cursor_pos = if app_state.ui.show_login { login_state.current_cursor_pos() }
|
||||
else if app_state.ui.show_register { register_state.current_cursor_pos() }
|
||||
else { form_state.current_cursor_pos() };
|
||||
self.highlight_anchor = Some((current_field_index, current_cursor_pos));
|
||||
self.command_message = "-- HIGHLIGHT --".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_edit_mode_before")
|
||||
&& ModeManager::can_enter_edit_mode(current_mode) {
|
||||
self.is_edit_mode = true;
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Edit mode".to_string();
|
||||
@@ -225,8 +239,8 @@ impl EventHandler {
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
||||
ModeManager::can_enter_edit_mode(current_mode) {
|
||||
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_edit_mode_after")
|
||||
&& ModeManager::can_enter_edit_mode(current_mode) {
|
||||
let current_input = if app_state.ui.show_login || app_state.ui.show_register{
|
||||
login_state.get_current_input()
|
||||
} else {
|
||||
@@ -306,8 +320,28 @@ impl EventHandler {
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
},
|
||||
|
||||
AppMode::Highlight => {
|
||||
if config.get_highlight_action_for_key(key_code, modifiers) == Some("exit_highlight_mode") {
|
||||
self.is_highlight_mode = false;
|
||||
self.highlight_anchor = None;
|
||||
self.command_message = "Exited highlight mode".to_string();
|
||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
let (_should_exit, message) = read_only::handle_read_only_event(
|
||||
app_state, key, config, form_state, login_state,
|
||||
register_state, &mut self.key_sequence_tracker,
|
||||
current_position, total_count, grpc_client,
|
||||
&mut self.command_message, &mut self.edit_mode_cooldown,
|
||||
&mut self.ideal_cursor_column,
|
||||
)
|
||||
.await?;
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
}
|
||||
|
||||
AppMode::Edit => {
|
||||
if config.is_exit_edit_mode(key_code, modifiers) {
|
||||
if config.get_edit_action_for_key(key_code, modifiers) == Some("exit_edit_mode") {
|
||||
self.is_edit_mode = false;
|
||||
self.edit_mode_cooldown = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user