feat: right Arrow to modify selected command (#2453)

* right arrow functionality

* use or within match

* handles cursor not at end of line

* left cursor exits at start

* cargo fmt
This commit is contained in:
Braelyn Boynton 2024-11-19 10:59:16 -08:00 committed by GitHub
parent 6ab61e48d0
commit 4f0084a8c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -203,6 +203,10 @@ impl Cursor {
pub fn start(&mut self) { pub fn start(&mut self) {
self.index = 0; self.index = 0;
} }
pub fn position(&self) -> usize {
self.index
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -205,6 +205,9 @@ impl State {
let ctrl = input.modifiers.contains(KeyModifiers::CONTROL); let ctrl = input.modifiers.contains(KeyModifiers::CONTROL);
let esc_allow_exit = !(self.tab_index == 0 && self.keymap_mode == KeymapMode::VimInsert); let esc_allow_exit = !(self.tab_index == 0 && self.keymap_mode == KeymapMode::VimInsert);
let cursor_at_end_of_line =
self.search.input.position() == UnicodeWidthStr::width(self.search.input.as_str());
let cursor_at_start_of_line = self.search.input.position() == 0;
// support ctrl-a prefix, like screen or tmux // support ctrl-a prefix, like screen or tmux
if !self.prefix if !self.prefix
@ -221,12 +224,14 @@ impl State {
KeyCode::Esc if esc_allow_exit => Some(Self::handle_key_exit(settings)), KeyCode::Esc if esc_allow_exit => Some(Self::handle_key_exit(settings)),
KeyCode::Char('[') if ctrl && esc_allow_exit => Some(Self::handle_key_exit(settings)), KeyCode::Char('[') if ctrl && esc_allow_exit => Some(Self::handle_key_exit(settings)),
KeyCode::Tab => Some(InputAction::Accept(self.results_state.selected())), KeyCode::Tab => Some(InputAction::Accept(self.results_state.selected())),
KeyCode::Right if cursor_at_end_of_line => {
Some(InputAction::Accept(self.results_state.selected()))
}
KeyCode::Left if cursor_at_start_of_line => Some(Self::handle_key_exit(settings)),
KeyCode::Char('o') if ctrl => { KeyCode::Char('o') if ctrl => {
self.tab_index = (self.tab_index + 1) % TAB_TITLES.len(); self.tab_index = (self.tab_index + 1) % TAB_TITLES.len();
Some(InputAction::Continue) Some(InputAction::Continue)
} }
_ => None, _ => None,
}; };