better move around the form terminal
This commit is contained in:
@@ -128,13 +128,13 @@ pub fn render_form(
|
|||||||
}
|
}
|
||||||
if is_active {
|
if is_active {
|
||||||
if is_edit_mode {
|
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_x = input_rows[i].x + input.len() as u16;
|
||||||
let cursor_y = input_rows[i].y;
|
let cursor_y = input_rows[i].y;
|
||||||
f.set_cursor(cursor_x, cursor_y);
|
f.set_cursor(cursor_x, cursor_y);
|
||||||
} else {
|
} else {
|
||||||
// Read-only mode: block at start of field
|
// Read-only mode: cursor at current_cursor_pos
|
||||||
let cursor_x = input_rows[i].x;
|
let cursor_x = input_rows[i].x + form_state.current_cursor_pos as u16;
|
||||||
let cursor_y = input_rows[i].y;
|
let cursor_y = input_rows[i].y;
|
||||||
f.set_cursor(cursor_x, cursor_y);
|
f.set_cursor(cursor_x, cursor_y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,36 @@ impl EventHandler {
|
|||||||
return Ok((false, self.command_message.clone()));
|
return Ok((false, self.command_message.clone()));
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
match key.code {
|
||||||
KeyCode::Char(':') => {
|
KeyCode::Char(':') => {
|
||||||
self.command_mode = true;
|
self.command_mode = true;
|
||||||
@@ -147,13 +176,6 @@ impl EventHandler {
|
|||||||
self.command_input.clear();
|
self.command_input.clear();
|
||||||
self.command_message.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 {
|
if !self.edit_mode_cooldown {
|
||||||
let default_key = "i".to_string();
|
let default_key = "i".to_string();
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
// src/client/ui/handlers/form.rs
|
// src/client/ui/handlers/form.rs
|
||||||
|
|
||||||
use crate::client::components1::render_form;
|
use crate::client::components1::render_form;
|
||||||
use crate::client::colors::Theme;
|
use crate::client::colors::Theme;
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
|
|
||||||
pub struct FormState {
|
pub struct FormState {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
|
|
||||||
pub firma: String,
|
pub firma: String,
|
||||||
pub kz: String,
|
pub kz: String,
|
||||||
pub drc: String,
|
pub drc: String,
|
||||||
@@ -23,12 +20,11 @@ pub struct FormState {
|
|||||||
pub telefon: String,
|
pub telefon: String,
|
||||||
pub skladu: String,
|
pub skladu: String,
|
||||||
pub fax: String,
|
pub fax: String,
|
||||||
|
|
||||||
pub current_field: usize,
|
pub current_field: usize,
|
||||||
pub fields: Vec<&'static str>,
|
pub fields: Vec<&'static str>,
|
||||||
pub has_unsaved_changes: bool,
|
pub has_unsaved_changes: bool,
|
||||||
|
pub current_cursor_pos: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormState {
|
impl FormState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
FormState {
|
FormState {
|
||||||
@@ -50,13 +46,13 @@ impl FormState {
|
|||||||
fax: String::new(),
|
fax: String::new(),
|
||||||
current_field: 0,
|
current_field: 0,
|
||||||
has_unsaved_changes: false,
|
has_unsaved_changes: false,
|
||||||
|
current_cursor_pos: 0,
|
||||||
fields: vec![
|
fields: vec![
|
||||||
"Firma", "KZ", "DRC", "Ulica", "PSC", "Mesto", "Stat", "Banka",
|
"Firma", "KZ", "DRC", "Ulica", "PSC", "Mesto", "Stat", "Banka",
|
||||||
"Ucet", "Skladm", "ICO", "Kontakt", "Telefon", "Skladu", "Fax",
|
"Ucet", "Skladm", "ICO", "Kontakt", "Telefon", "Skladu", "Fax",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(
|
pub fn render(
|
||||||
&self,
|
&self,
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
@@ -100,4 +96,25 @@ impl FormState {
|
|||||||
self.fax.clear();
|
self.fax.clear();
|
||||||
self.has_unsaved_changes = false;
|
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,
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user