Skip to content

Commit 7d9a1c9

Browse files
committed
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).
1 parent ea64fc4 commit 7d9a1c9

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

doc/tofi.1.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ displays a graphical selection menu. When a selection is made, it is
1919
printed to stdout.
2020

2121
When invoked via the name **tofi-run**, **tofi** will not accept items
22-
on stdin, instead presenting a list of executables in the user's $PATH.
22+
on stdin, instead presenting a list of executables in the user's \$PATH.
2323

2424
When invoked via the name **tofi-drun**, **tofi** will not accept items
2525
on stdin, and will generate a list of applications from desktop files as
@@ -55,6 +55,14 @@ the form **--key=value**.
5555

5656
> Move the selection forward one entry.
5757
58+
\<Ctrl\>-u
59+
60+
> Delete line.
61+
62+
\<Ctrl\>-w
63+
64+
> Delete word.
65+
5866
\<Enter\>
5967

6068
> Confirm the current selection and quit.
@@ -69,24 +77,24 @@ the form **--key=value**.
6977

7078
> Example configuration file.
7179
72-
*$XDG_CONFIG_HOME/tofi/config*
80+
*\$XDG_CONFIG_HOME/tofi/config*
7381

7482
> The default configuration file location.
7583
76-
*$XDG_CACHE_HOME/tofi-compgen*
84+
*\$XDG_CACHE_HOME/tofi-compgen*
7785

78-
> Cached list of executables under $PATH, regenerated as necessary.
86+
> Cached list of executables under \$PATH, regenerated as necessary.
7987
80-
*$XDG_CACHE_HOME/tofi-drun*
88+
*\$XDG_CACHE_HOME/tofi-drun*
8189

8290
> Cached list of desktop applications, regenerated as necessary.
8391
84-
*$XDG_STATE_HOME/tofi-history*
92+
*\$XDG_STATE_HOME/tofi-history*
8593

8694
> Numeric count of commands selected in **tofi-run**, to enable sorting
8795
> results by run count.
8896
89-
*$XDG_STATE_HOME/tofi-drun-history*
97+
*\$XDG_STATE_HOME/tofi-drun-history*
9098

9199
> Numeric count of commands selected in **tofi-drun**, to enable sorting
92100
> results by run count.

doc/tofi.1.scd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ All config file options described in *tofi*(5) are also accepted, in the form
5050
<Down> | <Right> | <Ctrl>-j | <Tab>
5151
Move the selection forward one entry.
5252

53+
<Ctrl>-u
54+
Delete line.
55+
56+
<Ctrl>-w
57+
Delete word.
58+
5359
<Enter>
5460
Confirm the current selection and quit.
5561

src/main.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,26 @@ static void handle_keypress(struct tofi *tofi, xkb_keycode_t keycode)
177177
string_vec_destroy(&tmp);
178178
}
179179
}
180-
} else if (entry->input_length > 0 && sym == XKB_KEY_BackSpace) {
181-
entry->input_length--;
182-
entry->input[entry->input_length] = L'\0';
180+
} else if (entry->input_length > 0
181+
&& (sym == XKB_KEY_BackSpace
182+
|| (sym == XKB_KEY_w
183+
&& xkb_state_mod_name_is_active(
184+
tofi->xkb_state,
185+
XKB_MOD_NAME_CTRL,
186+
XKB_STATE_MODS_EFFECTIVE))))
187+
{
188+
if (sym == XKB_KEY_BackSpace) {
189+
entry->input_length--;
190+
entry->input[entry->input_length] = L'\0';
191+
} else {
192+
while (entry->input_length > 0 && iswspace(entry->input[entry->input_length - 1])) {
193+
entry->input_length--;
194+
}
195+
while (entry->input_length > 0 && !iswspace(entry->input[entry->input_length - 1])) {
196+
entry->input_length--;
197+
}
198+
entry->input[entry->input_length] = L'\0';
199+
}
183200
const wchar_t *src = entry->input;
184201
size_t siz = wcsrtombs(
185202
entry->input_mb,
@@ -193,6 +210,23 @@ static void handle_keypress(struct tofi *tofi, xkb_keycode_t keycode)
193210
} else {
194211
entry->results = string_vec_filter(&entry->commands, entry->input_mb, tofi->fuzzy_match);
195212
}
213+
} else if (sym == XKB_KEY_u
214+
&& xkb_state_mod_name_is_active(
215+
tofi->xkb_state,
216+
XKB_MOD_NAME_CTRL,
217+
XKB_STATE_MODS_EFFECTIVE)
218+
)
219+
{
220+
entry->input_length = 0;
221+
entry->input[0] = L'\0';
222+
entry->input_mb_length = 0;
223+
entry->input_mb[0] = '\0';
224+
string_vec_destroy(&entry->results);
225+
if (entry->drun) {
226+
entry->results = desktop_vec_filter(&entry->apps, entry->input_mb, tofi->fuzzy_match);
227+
} else {
228+
entry->results = string_vec_filter(&entry->commands, entry->input_mb, tofi->fuzzy_match);
229+
}
196230
} else if (sym == XKB_KEY_Escape
197231
|| (sym == XKB_KEY_c
198232
&& xkb_state_mod_name_is_active(

0 commit comments

Comments
 (0)