form is now working as expected
This commit is contained in:
@@ -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<String> {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user