From dc232b2523e0e3c4739227fb2bcf67f9d0c6db73 Mon Sep 17 00:00:00 2001 From: filipriec Date: Sat, 7 Jun 2025 15:25:35 +0200 Subject: [PATCH] form is now working as expected --- client/src/tui/functions/form.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/client/src/tui/functions/form.rs b/client/src/tui/functions/form.rs index 986c45e..f081d44 100644 --- a/client/src/tui/functions/form.rs +++ b/client/src/tui/functions/form.rs @@ -1,5 +1,5 @@ // src/tui/functions/form.rs -use crate::state::pages::canvas_state::CanvasState; // Import the trait +use crate::state::pages::canvas_state::CanvasState; use crate::state::pages::form::FormState; use crate::services::grpc_client::GrpcClient; use anyhow::{anyhow, Result}; @@ -10,7 +10,6 @@ pub async fn handle_action( _grpc_client: &mut GrpcClient, ideal_cursor_column: &mut usize, ) -> Result { - // FIX: Call has_unsaved_changes() via the CanvasState trait. if form_state.has_unsaved_changes() { return Ok( "Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating." @@ -22,22 +21,20 @@ pub async fn handle_action( match action { "previous_entry" => { - if total_count > 0 { - if form_state.current_position > 1 { - form_state.current_position -= 1; - } else { - form_state.current_position = total_count; - } + // Only decrement if the current position is greater than the first record. + // This prevents wrapping from 1 to total_count. + // It also correctly handles moving from "New Entry" (total_count + 1) to the last record. + if form_state.current_position > 1 { + form_state.current_position -= 1; *ideal_cursor_column = 0; } } "next_entry" => { - if total_count > 0 { - if form_state.current_position < total_count { - form_state.current_position += 1; - } else { - form_state.current_position = 1; - } + // Only increment if the current position is not yet at the "New Entry" stage. + // The "New Entry" position is total_count + 1. + // This allows moving from the last record to "New Entry", but stops there. + if form_state.current_position <= total_count { + form_state.current_position += 1; *ideal_cursor_column = 0; } }