diff --git a/src/client/components1/handlers/form.rs b/src/client/components1/handlers/form.rs index 1c756b2..b271ae6 100644 --- a/src/client/components1/handlers/form.rs +++ b/src/client/components1/handlers/form.rs @@ -128,13 +128,13 @@ pub fn render_form( } if is_active { if is_edit_mode { - // Edit mode: vertical line at end of input + // Edit mode: cursor at the end let cursor_x = input_rows[i].x + input.len() as u16; let cursor_y = input_rows[i].y; f.set_cursor(cursor_x, cursor_y); } else { - // Read-only mode: block at start of field - let cursor_x = input_rows[i].x; + // Read-only mode: cursor at current_cursor_pos + let cursor_x = input_rows[i].x + form_state.current_cursor_pos as u16; let cursor_y = input_rows[i].y; f.set_cursor(cursor_x, cursor_y); } diff --git a/src/client/ui/handlers/event.rs b/src/client/ui/handlers/event.rs index 870c188..39d75b7 100644 --- a/src/client/ui/handlers/event.rs +++ b/src/client/ui/handlers/event.rs @@ -135,7 +135,36 @@ impl EventHandler { return Ok((false, self.command_message.clone())); } } else { - // Handle other read-only mode keys + // Check for movement keybindings + if let Some(action) = config.get_action_for_key(key.code, key.modifiers) { + match action { + "move_left" => { + form_state.current_cursor_pos = form_state.current_cursor_pos.saturating_sub(1); + return Ok((false, "".to_string())); + } + "move_right" => { + let current_input = form_state.get_current_input(); + if form_state.current_cursor_pos < current_input.len() { + form_state.current_cursor_pos += 1; + } + return Ok((false, "".to_string())); + } + "move_up" => { + form_state.current_field = form_state.current_field.saturating_sub(1); + let current_input = form_state.get_current_input(); + form_state.current_cursor_pos = form_state.current_cursor_pos.min(current_input.len()); + return Ok((false, "".to_string())); + } + "move_down" => { + form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(); + let current_input = form_state.get_current_input(); + form_state.current_cursor_pos = form_state.current_cursor_pos.min(current_input.len()); + return Ok((false, "".to_string())); + } + _ => {} + } + } + // Handle other keys (e.g., command mode) match key.code { KeyCode::Char(':') => { self.command_mode = true; @@ -147,13 +176,6 @@ impl EventHandler { self.command_input.clear(); self.command_message.clear(); } - KeyCode::Tab | KeyCode::BackTab | KeyCode::Down | KeyCode::Up => { - if key.modifiers.contains(KeyModifiers::SHIFT) { - form_state.current_field = form_state.current_field.saturating_sub(1); - } else { - form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(); - } - } _ => { if !self.edit_mode_cooldown { let default_key = "i".to_string(); diff --git a/src/client/ui/handlers/form.rs b/src/client/ui/handlers/form.rs index c7c33a6..284c2c3 100644 --- a/src/client/ui/handlers/form.rs +++ b/src/client/ui/handlers/form.rs @@ -1,13 +1,10 @@ // src/client/ui/handlers/form.rs - use crate::client::components1::render_form; use crate::client::colors::Theme; use ratatui::layout::Rect; use ratatui::Frame; - pub struct FormState { pub id: i64, - pub firma: String, pub kz: String, pub drc: String, @@ -23,12 +20,11 @@ pub struct FormState { pub telefon: String, pub skladu: String, pub fax: String, - pub current_field: usize, pub fields: Vec<&'static str>, pub has_unsaved_changes: bool, + pub current_cursor_pos: usize, } - impl FormState { pub fn new() -> Self { FormState { @@ -50,13 +46,13 @@ impl FormState { fax: String::new(), current_field: 0, has_unsaved_changes: false, + current_cursor_pos: 0, fields: vec![ "Firma", "KZ", "DRC", "Ulica", "PSC", "Mesto", "Stat", "Banka", "Ucet", "Skladm", "ICO", "Kontakt", "Telefon", "Skladu", "Fax", ], } } - pub fn render( &self, f: &mut Frame, @@ -100,4 +96,25 @@ impl FormState { self.fax.clear(); self.has_unsaved_changes = false; } + + pub fn get_current_input(&self) -> &str { + match self.current_field { + 0 => &self.firma, + 1 => &self.kz, + 2 => &self.drc, + 3 => &self.ulica, + 4 => &self.psc, + 5 => &self.mesto, + 6 => &self.stat, + 7 => &self.banka, + 8 => &self.ucet, + 9 => &self.skladm, + 10 => &self.ico, + 11 => &self.kontakt, + 12 => &self.telefon, + 13 => &self.skladu, + 14 => &self.fax, + _ => "", + } + } }