highlight is now working properly well, can keep on going

This commit is contained in:
filipriec
2025-04-15 23:46:57 +02:00
parent 415bc2044d
commit af4567aa3d
9 changed files with 107 additions and 82 deletions

View File

@@ -54,6 +54,7 @@ pub struct EventHandler {
pub command_message: String,
pub is_edit_mode: bool,
pub is_highlight_mode: bool,
pub is_linewise_highlight: bool,
pub highlight_anchor: Option<(usize, usize)>,
pub edit_mode_cooldown: bool,
pub ideal_cursor_column: usize,
@@ -69,6 +70,7 @@ impl EventHandler {
command_message: String::new(),
is_edit_mode: false,
is_highlight_mode: false,
is_linewise_highlight: false,
highlight_anchor: None,
edit_mode_cooldown: false,
ideal_cursor_column: 0,
@@ -216,9 +218,24 @@ impl EventHandler {
},
AppMode::ReadOnly => {
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_highlight_mode")
// Check for Linewise highlight first
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_highlight_mode_linewise")
&& ModeManager::can_enter_highlight_mode(current_mode) {
self.is_highlight_mode = true;
self.is_linewise_highlight = true; // Set linewise flag
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() };
// For linewise, anchor char doesn't matter, use 0
self.highlight_anchor = Some((current_field_index, 0));
self.command_message = "-- LINE HIGHLIGHT --".to_string();
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
// Check for Character-wise highlight
else 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;
self.is_linewise_highlight = false; // Ensure linewise is false
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() };
@@ -229,8 +246,8 @@ impl EventHandler {
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")
// Check for entering edit mode (before cursor)
else 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;
@@ -238,8 +255,8 @@ impl EventHandler {
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_edit_mode_after")
// Check for entering edit mode (after cursor)
else 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()
@@ -267,21 +284,17 @@ impl EventHandler {
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
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) {
// Check for entering command mode
else if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_command_mode")
&& ModeManager::can_enter_command_mode(current_mode) {
self.command_mode = true;
self.command_input.clear();
self.command_message.clear();
return Ok(EventOutcome::Ok(String::new()));
}
}
if let Some(action) = config.get_action_for_key_in_mode(
&config.keybindings.common,
key_code,
modifiers
) {
// Check for common actions (save, quit, etc.) only if no mode change happened
if let Some(action) = config.get_common_action(key_code, modifiers) {
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
return common_mode::handle_core_action(
@@ -302,6 +315,7 @@ impl EventHandler {
}
}
// If no mode change or specific common action handled, delegate to read_only handler
let (_should_exit, message) = read_only::handle_read_only_event(
app_state,
key,
@@ -317,8 +331,9 @@ impl EventHandler {
&mut self.edit_mode_cooldown,
&mut self.ideal_cursor_column,
).await?;
// Note: handle_read_only_event should ignore mode entry keys internally now
return Ok(EventOutcome::Ok(message));
},
}, // End AppMode::ReadOnly
AppMode::Highlight => {
if config.get_highlight_action_for_key(key_code, modifiers) == Some("exit_highlight_mode") {