diff --git a/client/src/modes/canvas/read_only.rs b/client/src/modes/canvas/read_only.rs index 163b3b2..2d9f76c 100644 --- a/client/src/modes/canvas/read_only.rs +++ b/client/src/modes/canvas/read_only.rs @@ -1,4 +1,5 @@ -// src/modes/handlers/read_only.rs + +// src/modes/canvas/read_only.rs use crossterm::event::{KeyEvent}; use crate::config::binds::config::Config; @@ -14,6 +15,7 @@ enum CharType { } pub async fn handle_read_only_event( + app_state: &crate::state::state::AppState, key: KeyEvent, config: &Config, form_state: &mut FormState, @@ -50,16 +52,27 @@ pub async fn handle_read_only_event( // Try to match the current sequence against Read-Only mode bindings if let Some(action) = config.matches_key_sequence_generalized(&sequence) { - let result = execute_action( - action, - form_state, - ideal_cursor_column, - key_sequence_tracker, - command_message, - current_position, - total_count, - grpc_client, - ).await?; + let result = if action == "previous_entry" && app_state.ui.show_form { + crate::tui::functions::form::handle_action( + action, + form_state, + grpc_client, + current_position, + total_count, + ideal_cursor_column, + ).await? + } else { + execute_action( + action, + form_state, + ideal_cursor_column, + key_sequence_tracker, + command_message, + current_position, + total_count, + grpc_client, + ).await? + }; key_sequence_tracker.reset(); return Ok((false, result)); } @@ -72,16 +85,27 @@ pub async fn handle_read_only_event( // Since it's not part of a multi-key sequence, check for a direct action if sequence.len() == 1 && !config.is_key_sequence_prefix(&sequence) { if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) { - let result = execute_action( - action, - form_state, - ideal_cursor_column, - key_sequence_tracker, - command_message, - current_position, - total_count, - grpc_client, - ).await?; + let result = if action == "previous_entry" && app_state.ui.show_form { + crate::tui::functions::form::handle_action( + action, + form_state, + grpc_client, + current_position, + total_count, + ideal_cursor_column, + ).await? + } else { + execute_action( + action, + form_state, + ideal_cursor_column, + key_sequence_tracker, + command_message, + current_position, + total_count, + grpc_client, + ).await? + }; key_sequence_tracker.reset(); return Ok((false, result)); } @@ -91,16 +115,27 @@ pub async fn handle_read_only_event( key_sequence_tracker.reset(); if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) { - let result = execute_action( - action, - form_state, - ideal_cursor_column, - key_sequence_tracker, - command_message, - current_position, - total_count, - grpc_client, - ).await?; + let result = if action == "previous_entry" && app_state.ui.show_form { + crate::tui::functions::form::handle_action( + action, + form_state, + grpc_client, + current_position, + total_count, + ideal_cursor_column, + ).await? + } else { + execute_action( + action, + form_state, + ideal_cursor_column, + key_sequence_tracker, + command_message, + current_position, + total_count, + grpc_client, + ).await? + }; return Ok((false, result)); } } @@ -134,6 +169,7 @@ async fn execute_action( *current_position = new_position; match grpc_client.get_adresar_by_position(*current_position).await { Ok(response) => { + // Replace update_from_response with direct field assignments form_state.id = response.id; form_state.values = vec![ response.firma, response.kz, response.drc, diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 6e8faac..e870df0 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -141,6 +141,7 @@ impl EventHandler { // Let read_only mode handle its own actions (including navigation from common bindings) return read_only::handle_read_only_event( + &app_state, key, config, form_state, diff --git a/client/src/state/pages/form.rs b/client/src/state/pages/form.rs index 0590993..7e03882 100644 --- a/client/src/state/pages/form.rs +++ b/client/src/state/pages/form.rs @@ -73,7 +73,7 @@ impl FormState { .expect("Invalid current_field index") } - fn update_from_response(&mut self, response: common::proto::multieko2::adresar::AdresarResponse) { + pub fn update_from_response(&mut self, response: common::proto::multieko2::adresar::AdresarResponse) { self.id = response.id; self.values = vec![ response.firma, response.kz, response.drc, diff --git a/client/src/tui/functions/form.rs b/client/src/tui/functions/form.rs index e69de29..da62771 100644 --- a/client/src/tui/functions/form.rs +++ b/client/src/tui/functions/form.rs @@ -0,0 +1,30 @@ +// src/tui/functions/form.rs + +use crate::state::pages::form::FormState; +use crate::tui::terminal::GrpcClient; + +pub async fn handle_action( + action: &str, + form_state: &mut FormState, + grpc_client: &mut GrpcClient, + current_position: &mut u64, + total_count: u64, + ideal_cursor_column: &mut usize, +) -> Result> { + match action { + "previous_entry" => { + // Form-specific previous entry logic + let new_position = current_position.saturating_sub(1); + if new_position >= 1 { + *current_position = new_position; + let response = grpc_client.get_adresar_by_position(*current_position).await?; + form_state.update_from_response(response); + Ok(format!("Loaded form entry {}", *current_position)) + } else { + Ok("Already at first form entry".into()) + } + } + // Other form-specific actions... + _ => Err("Unknown form action".into()) + } +}