Skip to content

Commit

Permalink
handles cursor not at end of line
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 committed Nov 19, 2024
1 parent fbb1a5f commit 5ef771a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/atuin/src/command/client/search/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ impl Cursor {
pub fn start(&mut self) {
self.index = 0;
}

pub fn position(&self) -> usize {
self.index
}
}

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion crates/atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ impl State {

let ctrl = input.modifiers.contains(KeyModifiers::CONTROL);
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());

// support ctrl-a prefix, like screen or tmux
if !self.prefix
Expand All @@ -220,11 +221,12 @@ impl State {
KeyCode::Char('c' | 'g') if ctrl => Some(InputAction::ReturnOriginal),
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::Tab => Some(InputAction::Accept(self.results_state.selected())),
KeyCode::Right if cursor_at_end_of_line => Some(InputAction::Accept(self.results_state.selected())),
KeyCode::Char('o') if ctrl => {
self.tab_index = (self.tab_index + 1) % TAB_TITLES.len();
Some(InputAction::Continue)
},
KeyCode::Tab | KeyCode::Right => Some(InputAction::Accept(self.results_state.selected())),
_ => None,
};

Expand Down

0 comments on commit 5ef771a

Please sign in to comment.