form is now working as expected
This commit is contained in:
@@ -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.
|
||||||
|
// 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 {
|
if form_state.current_position > 1 {
|
||||||
form_state.current_position -= 1;
|
form_state.current_position -= 1;
|
||||||
} else {
|
|
||||||
form_state.current_position = total_count;
|
|
||||||
}
|
|
||||||
*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.
|
||||||
|
// 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;
|
form_state.current_position += 1;
|
||||||
} else {
|
|
||||||
form_state.current_position = 1;
|
|
||||||
}
|
|
||||||
*ideal_cursor_column = 0;
|
*ideal_cursor_column = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user