Skip to content

Commit 4f0084a

Browse files
authored
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
1 parent 6ab61e4 commit 4f0084a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

crates/atuin/src/command/client/search/cursor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ impl Cursor {
203203
pub fn start(&mut self) {
204204
self.index = 0;
205205
}
206+
207+
pub fn position(&self) -> usize {
208+
self.index
209+
}
206210
}
207211

208212
#[cfg(test)]

crates/atuin/src/command/client/search/interactive.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ impl State {
205205

206206
let ctrl = input.modifiers.contains(KeyModifiers::CONTROL);
207207
let esc_allow_exit = !(self.tab_index == 0 && self.keymap_mode == KeymapMode::VimInsert);
208+
let cursor_at_end_of_line =
209+
self.search.input.position() == UnicodeWidthStr::width(self.search.input.as_str());
210+
let cursor_at_start_of_line = self.search.input.position() == 0;
208211

209212
// support ctrl-a prefix, like screen or tmux
210213
if !self.prefix
@@ -221,12 +224,14 @@ impl State {
221224
KeyCode::Esc if esc_allow_exit => Some(Self::handle_key_exit(settings)),
222225
KeyCode::Char('[') if ctrl && esc_allow_exit => Some(Self::handle_key_exit(settings)),
223226
KeyCode::Tab => Some(InputAction::Accept(self.results_state.selected())),
227+
KeyCode::Right if cursor_at_end_of_line => {
228+
Some(InputAction::Accept(self.results_state.selected()))
229+
}
230+
KeyCode::Left if cursor_at_start_of_line => Some(Self::handle_key_exit(settings)),
224231
KeyCode::Char('o') if ctrl => {
225232
self.tab_index = (self.tab_index + 1) % TAB_TITLES.len();
226-
227233
Some(InputAction::Continue)
228234
}
229-
230235
_ => None,
231236
};
232237

0 commit comments

Comments
 (0)