working up down keys in the edit mode
This commit is contained in:
@@ -150,7 +150,12 @@ impl EventHandler {
|
|||||||
return Ok((false, "".to_string()));
|
return Ok((false, "".to_string()));
|
||||||
}
|
}
|
||||||
"move_up" => {
|
"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();
|
let current_input = form_state.get_current_input();
|
||||||
form_state.current_cursor_pos = form_state.current_cursor_pos.min(current_input.len());
|
form_state.current_cursor_pos = form_state.current_cursor_pos.min(current_input.len());
|
||||||
return Ok((false, "".to_string()));
|
return Ok((false, "".to_string()));
|
||||||
@@ -333,7 +338,12 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
KeyCode::Tab => {
|
KeyCode::Tab => {
|
||||||
if key.modifiers.contains(KeyModifiers::SHIFT) {
|
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 {
|
} else {
|
||||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
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()));
|
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::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::Enter => form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(),
|
||||||
KeyCode::Char(c) => {
|
KeyCode::Char(c) => {
|
||||||
match form_state.current_field {
|
match form_state.current_field {
|
||||||
|
|||||||
Reference in New Issue
Block a user