working up down keys in the edit mode

This commit is contained in:
filipriec
2025-02-20 13:15:46 +01:00
parent 5c85776b8a
commit 4cfef173ef

View File

@@ -150,7 +150,12 @@ impl EventHandler {
return Ok((false, "".to_string()));
}
"move_up" => {
form_state.current_field = form_state.current_field.saturating_sub(1);
if form_state.current_field == 0 {
// Wrap to the last field when at the top
form_state.current_field = form_state.fields.len() - 1;
} else {
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()));
@@ -333,7 +338,12 @@ impl EventHandler {
}
KeyCode::Tab => {
if key.modifiers.contains(KeyModifiers::SHIFT) {
form_state.current_field = form_state.current_field.saturating_sub(1);
if form_state.current_field == 0 {
// Wrap to the last field when at the top
form_state.current_field = form_state.fields.len() - 1;
} else {
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();
}
@@ -350,9 +360,23 @@ impl EventHandler {
return Ok((false, self.command_message.clone()));
}
}
KeyCode::BackTab => form_state.current_field = form_state.current_field.saturating_sub(1),
KeyCode::BackTab => {
if form_state.current_field == 0 {
// Wrap to the last field when at the top
form_state.current_field = form_state.fields.len() - 1;
} else {
form_state.current_field = form_state.current_field.saturating_sub(1);
}
},
KeyCode::Down => form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(),
KeyCode::Up => form_state.current_field = form_state.current_field.saturating_sub(1),
KeyCode::Up => {
if form_state.current_field == 0 {
// Wrap to the last field when at the top
form_state.current_field = form_state.fields.len() - 1;
} else {
form_state.current_field = form_state.current_field.saturating_sub(1);
}
},
KeyCode::Enter => form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(),
KeyCode::Char(c) => {
match form_state.current_field {