From 7d9a1c9b401e83ea642892535c399f906b2defa6 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sat, 20 Aug 2022 10:16:48 +0100 Subject: 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). --- src/main.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 7d861b4..9f244af 100644 --- a/src/main.c +++ b/src/main.c @@ -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( -- cgit v1.2.3