form is now working as expected

This commit is contained in:
filipriec
2025-06-07 15:25:35 +02:00
parent b086b3e236
commit dc232b2523

View File

@@ -1,5 +1,5 @@
// src/tui/functions/form.rs // 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::state::pages::form::FormState;
use crate::services::grpc_client::GrpcClient; use crate::services::grpc_client::GrpcClient;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
@@ -10,7 +10,6 @@ pub async fn handle_action(
_grpc_client: &mut GrpcClient, _grpc_client: &mut GrpcClient,
ideal_cursor_column: &mut usize, ideal_cursor_column: &mut usize,
) -> Result<String> { ) -> Result<String> {
// FIX: Call has_unsaved_changes() via the CanvasState trait.
if form_state.has_unsaved_changes() { if form_state.has_unsaved_changes() {
return Ok( return Ok(
"Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating." "Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating."
@@ -22,22 +21,20 @@ pub async fn handle_action(
match action { match action {
"previous_entry" => { "previous_entry" => {
if total_count > 0 { // Only decrement if the current position is greater than the first record.
if form_state.current_position > 1 { // This prevents wrapping from 1 to total_count.
form_state.current_position -= 1; // It also correctly handles moving from "New Entry" (total_count + 1) to the last record.
} else { if form_state.current_position > 1 {
form_state.current_position = total_count; form_state.current_position -= 1;
}
*ideal_cursor_column = 0; *ideal_cursor_column = 0;
} }
} }
"next_entry" => { "next_entry" => {
if total_count > 0 { // Only increment if the current position is not yet at the "New Entry" stage.
if form_state.current_position < total_count { // The "New Entry" position is total_count + 1.
form_state.current_position += 1; // This allows moving from the last record to "New Entry", but stops there.
} else { if form_state.current_position <= total_count {
form_state.current_position = 1; form_state.current_position += 1;
}
*ideal_cursor_column = 0; *ideal_cursor_column = 0;
} }
} }