diff options
author | Phil Jones <philj56@gmail.com> | 2022-08-20 10:16:48 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-08-20 10:16:48 +0100 |
commit | 7d9a1c9b401e83ea642892535c399f906b2defa6 (patch) | |
tree | 8eb6d1337edeb7d1f8e431cc42e78b7690c6782d /src/main.c | |
parent | ea64fc43a6a321fcc7417f35d5ce50a2c7ee9d7e (diff) |
Add Ctrl-u and Ctrl-w readline bindings.
Ctrl-u is just a whole line delete for now, as there's no sense of a
cursor position in tofi (so the whole line is "left" of the cursor).
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 40 |
1 files changed, 37 insertions, 3 deletions
@@ -177,9 +177,26 @@ static void handle_keypress(struct tofi *tofi, xkb_keycode_t keycode) string_vec_destroy(&tmp); } } - } else if (entry->input_length > 0 && sym == XKB_KEY_BackSpace) { - entry->input_length--; - entry->input[entry->input_length] = L'\0'; + } else if (entry->input_length > 0 + && (sym == XKB_KEY_BackSpace + || (sym == XKB_KEY_w + && xkb_state_mod_name_is_active( + tofi->xkb_state, + XKB_MOD_NAME_CTRL, + XKB_STATE_MODS_EFFECTIVE)))) + { + if (sym == XKB_KEY_BackSpace) { + entry->input_length--; + entry->input[entry->input_length] = L'\0'; + } else { + while (entry->input_length > 0 && iswspace(entry->input[entry->input_length - 1])) { + entry->input_length--; + } + while (entry->input_length > 0 && !iswspace(entry->input[entry->input_length - 1])) { + entry->input_length--; + } + entry->input[entry->input_length] = L'\0'; + } const wchar_t *src = entry->input; size_t siz = wcsrtombs( entry->input_mb, @@ -193,6 +210,23 @@ static void handle_keypress(struct tofi *tofi, xkb_keycode_t keycode) } else { entry->results = string_vec_filter(&entry->commands, entry->input_mb, tofi->fuzzy_match); } + } else if (sym == XKB_KEY_u + && xkb_state_mod_name_is_active( + tofi->xkb_state, + XKB_MOD_NAME_CTRL, + XKB_STATE_MODS_EFFECTIVE) + ) + { + entry->input_length = 0; + entry->input[0] = L'\0'; + entry->input_mb_length = 0; + entry->input_mb[0] = '\0'; + string_vec_destroy(&entry->results); + if (entry->drun) { + entry->results = desktop_vec_filter(&entry->apps, entry->input_mb, tofi->fuzzy_match); + } else { + entry->results = string_vec_filter(&entry->commands, entry->input_mb, tofi->fuzzy_match); + } } else if (sym == XKB_KEY_Escape || (sym == XKB_KEY_c && xkb_state_mod_name_is_active( |