Skip to content

Commit

Permalink
feat(#9): add more readline bindings (#9)
Browse files Browse the repository at this point in the history
Adds new readline bindings for moving the cursor and deleting
characters. ctrl-k is not included due to being used for moving
selection down with vi-like keybinds, and is conventional (used in fzf
and fzy). A future feature should add an environment variable to control
emacs/vi bindings.
  • Loading branch information
jmbaur authored Mar 14, 2022
1 parent cc7c2c3 commit 9c7a784
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ const Action = union(enum) {
line_up,
line_down,
cursor_left,
cursor_leftmost,
cursor_right,
cursor_rightmost,
backspace,
delete,
delete_word,
Expand All @@ -311,6 +313,12 @@ fn ctrlToAction(key: u8) Action {
ctrl('c') => .close,
ctrl('w') => .delete_word,
ctrl('u') => .delete_line,
ctrl('h') => .backspace,
ctrl('a') => .cursor_leftmost,
ctrl('e') => .cursor_rightmost,
ctrl('d') => .delete,
ctrl('f') => .cursor_right,
ctrl('b') => .cursor_left,
ctrl('p'), ctrl('k') => .line_up,
ctrl('n'), ctrl('j') => .line_down,
else => .pass,
Expand Down Expand Up @@ -445,6 +453,12 @@ pub fn run(
.cursor_left => if (state.cursor > 0) {
state.cursor -= 1;
},
.cursor_leftmost => if (state.cursor > 0) {
state.cursor = 0;
},
.cursor_rightmost => if (state.cursor < query.items.len) {
state.cursor = query.items.len;
},
.cursor_right => if (state.cursor < query.items.len) {
state.cursor += 1;
},
Expand Down

0 comments on commit 9c7a784

Please sign in to comment.