diff --git a/client/src/ui/handlers/ui.rs b/client/src/ui/handlers/ui.rs index f29d1d8..077e333 100644 --- a/client/src/ui/handlers/ui.rs +++ b/client/src/ui/handlers/ui.rs @@ -66,6 +66,8 @@ pub async fn run_ui() -> Result<(), Box> { let total_count = app_state.total_count; let mut current_position = app_state.current_position; + // Store position before event handling to detect navigation + let position_before_event = current_position; let event = event_reader.read_event()?; let (should_exit, message) = event_handler.handle_event( @@ -83,9 +85,11 @@ pub async fn run_ui() -> Result<(), Box> { app_state.current_position = current_position; + let position_changed = app_state.current_position != position_before_event; + // Handle position changes and update form state (Only when form is shown) - if app_state.ui.show_form { // Added check - if !event_handler.is_edit_mode { + if app_state.ui.show_form { + if position_changed && !event_handler.is_edit_mode { let current_input = form_state.get_current_input(); let max_cursor_pos = if !current_input.is_empty() { current_input.len() - 1 // Limit to last character in readonly mode @@ -131,6 +135,16 @@ pub async fn run_ui() -> Result<(), Box> { form_state.current_field = 0; } } + } else if !position_changed && !event_handler.is_edit_mode { + // If position didn't change but we are in read-only, just adjust cursor + let current_input = form_state.get_current_input(); + let max_cursor_pos = if !current_input.is_empty() { + current_input.len() - 1 + } else { + 0 + }; + form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos); + } } else if app_state.ui.show_login { // Handle cursor updates for AuthState if needed, similar to FormState