feat(search): add delete-to-start and delete-to-end keybindings

with ctrl+u and ctrl+k respectively

Ref: #1972
This commit is contained in:
Adrian fxj9a 2025-03-03 14:27:30 +01:00
parent 882f4b2468
commit 41c3d1834c
No known key found for this signature in database
GPG key ID: FA1E6994A87D434E
4 changed files with 35 additions and 0 deletions

View file

@ -180,6 +180,8 @@ static const char *const search_binding_action_map[] = {
[BIND_ACTION_SEARCH_DELETE_PREV_WORD] = "delete-prev-word",
[BIND_ACTION_SEARCH_DELETE_NEXT] = "delete-next",
[BIND_ACTION_SEARCH_DELETE_NEXT_WORD] = "delete-next-word",
[BIND_ACTION_SEARCH_DELETE_TO_START] = "delete-to-start",
[BIND_ACTION_SEARCH_DELETE_TO_END] = "delete-to-end",
[BIND_ACTION_SEARCH_EXTEND_CHAR] = "extend-char",
[BIND_ACTION_SEARCH_EXTEND_WORD] = "extend-to-word-boundary",
[BIND_ACTION_SEARCH_EXTEND_WORD_WS] = "extend-to-next-whitespace",
@ -3183,6 +3185,8 @@ add_default_search_bindings(struct config *conf)
{BIND_ACTION_SEARCH_DELETE_NEXT, m("none"), {{XKB_KEY_Delete}}},
{BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_Delete}}},
{BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m(XKB_MOD_NAME_ALT), {{XKB_KEY_d}}},
{BIND_ACTION_SEARCH_DELETE_TO_START, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_u}}},
{BIND_ACTION_SEARCH_DELETE_TO_END, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_k}}},
{BIND_ACTION_SEARCH_EXTEND_CHAR, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Right}}},
{BIND_ACTION_SEARCH_EXTEND_WORD, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_Right}}},
{BIND_ACTION_SEARCH_EXTEND_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_w}}},

View file

@ -225,6 +225,8 @@
# delete-prev-word=Mod1+BackSpace Control+BackSpace
# delete-next=Delete
# delete-next-word=Mod1+d Control+Delete
# delete-to-start=Control+u
# delete-to-end=Control+k
# extend-char=Shift+Right
# extend-to-word-boundary=Control+w Control+Shift+Right
# extend-to-next-whitespace=Control+Shift+w

View file

@ -84,6 +84,8 @@ enum bind_action_search {
BIND_ACTION_SEARCH_DELETE_PREV_WORD,
BIND_ACTION_SEARCH_DELETE_NEXT,
BIND_ACTION_SEARCH_DELETE_NEXT_WORD,
BIND_ACTION_SEARCH_DELETE_TO_START,
BIND_ACTION_SEARCH_DELETE_TO_END,
BIND_ACTION_SEARCH_EXTEND_CHAR,
BIND_ACTION_SEARCH_EXTEND_WORD,
BIND_ACTION_SEARCH_EXTEND_WORD_WS,

View file

@ -1265,6 +1265,33 @@ execute_binding(struct seat *seat, struct terminal *term,
return true;
}
case BIND_ACTION_SEARCH_DELETE_TO_START: {
if (term->search.cursor > 0) {
memmove(&term->search.buf[0],
&term->search.buf[term->search.cursor],
(term->search.len - term->search.cursor)
* sizeof(char32_t));
term->search.len -= term->search.cursor;
term->search.cursor = 0;
*update_search_result = *redraw = true;
}
return true;
}
case BIND_ACTION_SEARCH_DELETE_TO_END: {
if (term->search.cursor < term->search.len) {
memmove(&term->search.buf[term->search.cursor],
&term->search.buf[term->search.len],
(term->search.len + term->search.cursor - term->search.len)
* sizeof(char32_t));
term->search.len = term->search.cursor;
*update_search_result = *redraw = true;
}
return true;
}
case BIND_ACTION_SEARCH_EXTEND_CHAR: {
struct coord target;
if (search_extend_find_char_right(term, &target)) {