feat: Prevent form navigation with unsaved changes
This commit is contained in:
@@ -27,13 +27,16 @@ pub fn render_canvas(
|
|||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
// Input container styling
|
// Input container styling
|
||||||
|
let border_style = if form_state.has_unsaved_changes() {
|
||||||
|
Style::default().fg(theme.warning)
|
||||||
|
} else if is_edit_mode {
|
||||||
|
Style::default().fg(theme.accent)
|
||||||
|
} else {
|
||||||
|
Style::default().fg(theme.secondary)
|
||||||
|
};
|
||||||
let input_container = Block::default()
|
let input_container = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_style(if is_edit_mode {
|
.border_style(border_style)
|
||||||
form_state.has_unsaved_changes().then(|| theme.warning).unwrap_or(theme.accent)
|
|
||||||
} else {
|
|
||||||
theme.secondary
|
|
||||||
})
|
|
||||||
.style(Style::default().bg(theme.bg));
|
.style(Style::default().bg(theme.bg));
|
||||||
|
|
||||||
// Input block dimensions
|
// Input block dimensions
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ pub async fn handle_action(
|
|||||||
total_count: u64,
|
total_count: u64,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
// TODO store unsaved changes without deleting form state values
|
||||||
|
// First check for unsaved changes in both cases
|
||||||
|
if form_state.has_unsaved_changes() {
|
||||||
|
return Ok(
|
||||||
|
"Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating."
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
"previous_entry" => {
|
"previous_entry" => {
|
||||||
let new_position = current_position.saturating_sub(1);
|
let new_position = current_position.saturating_sub(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user