From 946d6437742379c086654f9398e2912c984132c4 Mon Sep 17 00:00:00 2001 From: filipriec Date: Thu, 20 Feb 2025 22:06:30 +0100 Subject: [PATCH] scroll read only mode clipping cursor bug fixed --- config.toml | 4 ++-- src/client/ui/handlers/event.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config.toml b/config.toml index 18f6827..248fa12 100644 --- a/config.toml +++ b/config.toml @@ -11,5 +11,5 @@ next_position = ["Right", "8"] move_left = ["h"] move_right = ["l"] -# move_up = ["k", "Up"] -# move_down = ["j", "Down"] +move_up = ["k", "Up"] +move_down = ["j", "Down"] diff --git a/src/client/ui/handlers/event.rs b/src/client/ui/handlers/event.rs index dd5fd29..0bd0150 100644 --- a/src/client/ui/handlers/event.rs +++ b/src/client/ui/handlers/event.rs @@ -56,7 +56,7 @@ impl EventHandler { self.is_edit_mode = false; self.edit_mode_cooldown = true; self.command_message = "Read-only mode".to_string(); - app_terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?; // Add this line + app_terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?; return Ok((false, self.command_message.clone())); } @@ -86,7 +86,8 @@ impl EventHandler { form_state.skladu = response.skladu; form_state.fax = response.fax; - form_state.current_field = 0; + let current_input = form_state.get_current_input(); + form_state.current_cursor_pos = self.ideal_cursor_column.min(current_input.len()); form_state.has_unsaved_changes = false; self.command_message = format!("Loaded entry {}", *current_position); } @@ -123,7 +124,8 @@ impl EventHandler { form_state.skladu = response.skladu; form_state.fax = response.fax; - form_state.current_field = 0; + let current_input = form_state.get_current_input(); + form_state.current_cursor_pos = self.ideal_cursor_column.min(current_input.len()); form_state.has_unsaved_changes = false; self.command_message = format!("Loaded entry {}", *current_position); } @@ -135,6 +137,7 @@ impl EventHandler { // Clear form when entering new entry position form_state.reset_to_empty(); form_state.current_field = 0; + form_state.current_cursor_pos = 0; self.command_message = "New entry mode".to_string(); } return Ok((false, self.command_message.clone())); @@ -145,6 +148,7 @@ impl EventHandler { match action { "move_left" => { form_state.current_cursor_pos = form_state.current_cursor_pos.saturating_sub(1); + self.ideal_cursor_column = form_state.current_cursor_pos; return Ok((false, "".to_string())); } "move_right" => { @@ -152,6 +156,7 @@ impl EventHandler { if form_state.current_cursor_pos < current_input.len() { form_state.current_cursor_pos += 1; } + self.ideal_cursor_column = form_state.current_cursor_pos; return Ok((false, "".to_string())); } "move_up" => { @@ -162,13 +167,13 @@ impl EventHandler { form_state.current_field = form_state.current_field.saturating_sub(1); } let current_input = form_state.get_current_input(); - form_state.current_cursor_pos = form_state.current_cursor_pos.min(current_input.len()); + form_state.current_cursor_pos = self.ideal_cursor_column.min(current_input.len()); return Ok((false, "".to_string())); } "move_down" => { form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(); let current_input = form_state.get_current_input(); - form_state.current_cursor_pos = form_state.current_cursor_pos.min(current_input.len()); + form_state.current_cursor_pos = self.ideal_cursor_column.min(current_input.len()); return Ok((false, "".to_string())); } _ => {}