diff options
| author | Jack Jamison <jackqjamison@gmail.com> | 2025-11-04 19:30:26 -0500 |
|---|---|---|
| committer | Jack Jamison <jackqjamison@gmail.com> | 2025-11-06 19:45:03 -0500 |
| commit | 2fe0e7afd0da6bf128cd5d8d99180cc3a75eca0a (patch) | |
| tree | 87c6b71525ffb99e5ba5a26a550eb5673f3934d6 | |
| parent | 95fb3cad63941466e913775a3c080b310d45d13a (diff) | |
forward and backward word
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | input_field.c | 11 | ||||
| -rw-r--r-- | keybind.c | 44 | ||||
| -rw-r--r-- | keybind.h | 14 |
4 files changed, 62 insertions, 12 deletions
@@ -27,9 +27,10 @@ Q: What is an ENU? - [x] page scroll - [x] emacs keybindings - [x] "prompt" -- [ ] fuzzy filter +- [x] fuzzy filter - [ ] config file -- [ ] unicode + shaping +- [ ] scrolling in input +- [ ] unicode + text shaping Stretch: - [ ] input fluff (icons, descriptions, output names) diff --git a/input_field.c b/input_field.c index d24239c..ab0492f 100644 --- a/input_field.c +++ b/input_field.c @@ -104,7 +104,7 @@ key_repeat_t type_key(client_state* state, xkb_keysym_t keysym) { case XKB_KEY_p: return select_previous(state); case XKB_KEY_e: return goto_end(state); - case XKB_KEY_a: return goto_begining(state); + case XKB_KEY_a: return goto_start(state); case XKB_KEY_f: return forward_char(state); case XKB_KEY_b: return backward_char(state); @@ -114,15 +114,16 @@ key_repeat_t type_key(client_state* state, xkb_keysym_t keysym) { case XKB_KEY_v: return paste_from_clipboard(state); - case XKB_KEY_BackSpace: - case XKB_KEY_Delete: - return clear_input(state); + case XKB_KEY_BackSpace: return kill_to_start(state); + case XKB_KEY_Delete: return clear_input(state); } } else if (alt) { switch (keysym) { case XKB_KEY_d: return delete_word(state); - case XKB_KEY_BackSpace: return delete_word_backward(state); + case XKB_KEY_BackSpace: return delete_word_backward(state); + case XKB_KEY_f: return forward_word(state); + case XKB_KEY_b: return backward_word(state); } } switch (keysym) { @@ -61,7 +61,7 @@ key_repeat_t goto_end(client_state* state) { return KEY_NO_REPEAT; } -key_repeat_t goto_begining(client_state* state) { +key_repeat_t goto_start(client_state* state) { state->cursor_index = 0; return KEY_NO_REPEAT; } @@ -80,6 +80,48 @@ key_repeat_t backward_char(client_state* state) { return KEY_REPEAT; } +key_repeat_t forward_word(client_state* state) { + if (state->cursor_index < array_size(state->input_buffer)) { + bool hit_white = false; + for (; state->cursor_index < array_size(state->input_buffer); state->cursor_index++) { + if (state->input_buffer[state->cursor_index] == ' ') { + hit_white = true; + } else if (hit_white) { + break; + } + } + } + return KEY_REPEAT; +} + +key_repeat_t backward_word(client_state* state) { + if (state->cursor_index > 0) { + bool hit_non_white = false; + state->cursor_index--; + for (; state->cursor_index > 0; state->cursor_index--) { + if (state->input_buffer[state->cursor_index] == ' ') { + if (hit_non_white) { + ++state->cursor_index; + break; + } + } else { + hit_non_white = true; + } + } + } + return KEY_REPEAT; +} + +key_repeat_t kill_to_start(client_state* state) { + if (array_size(state->input_buffer) && state->cursor_index) { + array_erase_range(state->input_buffer, 0, state->cursor_index - 1); + state->cursor_index = 0; + update_text_buffer(state); + } + + return KEY_NO_REPEAT; +} + key_repeat_t kill_to_end(client_state* state) { array_resize(state->input_buffer, state->cursor_index); update_text_buffer(state); @@ -10,20 +10,26 @@ typedef bool key_repeat_t; #define KEY_NO_REPEAT 0 key_repeat_t quit(client_state* state); - key_repeat_t submit_line(client_state* state); -key_repeat_t insert_selected(client_state* state); - +// options key_repeat_t select_next(client_state* state); key_repeat_t select_previous(client_state* state); +// select first +// select last + +// input +key_repeat_t insert_selected(client_state* state); key_repeat_t goto_end(client_state* state); -key_repeat_t goto_begining(client_state* state); +key_repeat_t goto_start(client_state* state); key_repeat_t forward_char(client_state* state); key_repeat_t backward_char(client_state* state); +key_repeat_t forward_word(client_state* state); +key_repeat_t backward_word(client_state* state); +key_repeat_t kill_to_start(client_state* state); key_repeat_t kill_to_end(client_state* state); key_repeat_t delete_word(client_state* state); |
