From fc0a1923dc3ce53021f7524ec30434774c92bfe3 Mon Sep 17 00:00:00 2001 From: "lbia.xyz" Date: Fri, 24 Jun 2022 17:40:33 +0200 Subject: [PATCH] Add new key-binding: "extend-to-end-line" This new key-binding is similar to "extend-to-word-boundary" and "extend-to-next-whitespace", it applies in "scrollback search" mode and extends current selection to the end of the line. This commit also removes the parameter "bool spaces_only" from selection_find_line_boundary_right and selection_find_line_boundary_left since it is not used inside the functions --- README.md | 4 ++++ config.c | 2 ++ doc/foot.1.scd | 4 ++++ doc/foot.ini.5.scd | 4 ++++ foot.ini | 1 + key-binding.h | 1 + search.c | 20 +++++++++++++++----- selection.c | 18 ++++++++---------- selection.h | 3 +++ 9 files changed, 42 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 348f2e18..7ce31e50 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,10 @@ These are the default shortcuts. See `man foot.ini` and the example : Same as ctrl+w, except that the only word separating characters are whitespace characters. +ctrl+l +: Extend current selection (and thus the search criteria) to the end + of the line. + ctrl+v, ctrl+shift+v, ctrl+y, XF86Paste : Paste from clipboard into the search buffer. diff --git a/config.c b/config.c index ce0e27b8..e14dd343 100644 --- a/config.c +++ b/config.c @@ -146,6 +146,7 @@ static const char *const search_binding_action_map[] = { [BIND_ACTION_SEARCH_DELETE_NEXT_WORD] = "delete-next-word", [BIND_ACTION_SEARCH_EXTEND_WORD] = "extend-to-word-boundary", [BIND_ACTION_SEARCH_EXTEND_WORD_WS] = "extend-to-next-whitespace", + [BIND_ACTION_SEARCH_EXTEND_LINE] = "extend-to-end-line", [BIND_ACTION_SEARCH_CLIPBOARD_PASTE] = "clipboard-paste", [BIND_ACTION_SEARCH_PRIMARY_PASTE] = "primary-paste", }; @@ -2705,6 +2706,7 @@ add_default_search_bindings(struct config *conf) {BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m_alt, {{XKB_KEY_d}}}, {BIND_ACTION_SEARCH_EXTEND_WORD, m_ctrl, {{XKB_KEY_w}}}, {BIND_ACTION_SEARCH_EXTEND_WORD_WS, m_ctrl_shift, {{XKB_KEY_w}}}, + {BIND_ACTION_SEARCH_EXTEND_LINE, m_ctrl, {{XKB_KEY_l}}}, {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_ctrl, {{XKB_KEY_v}}}, {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_ctrl_shift, {{XKB_KEY_v}}}, {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_ctrl, {{XKB_KEY_y}}}, diff --git a/doc/foot.1.scd b/doc/foot.1.scd index afb8faf5..58dd4790 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -231,6 +231,10 @@ default) available; see *foot.ini*(5). Same as *ctrl*+*w*, except that the only word separating characters are whitespace characters. +*ctrl*+*l* + Extend current selection (and thus the search criteria) to the end + of the line. + *ctrl*+*v*, *ctrl*+*shift*+*v*, *ctrl*+*y*, *XF86Paste* Paste from clipboard into the search buffer. diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index bd551442..9a9e3a11 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -851,6 +851,10 @@ scrollback search mode. The syntax is exactly the same as the regular Extend the current selection to the next whitespace. Default: _Control+Shift+w_. +*extend-to-end-line* + Extend current selection to the end of the line. Default: + _Control+l_. + *clipboard-paste* Paste from the _clipboard_ into the search buffer. Default: _Control+v Control+y_. diff --git a/foot.ini b/foot.ini index 10eb56e8..7220294c 100644 --- a/foot.ini +++ b/foot.ini @@ -167,6 +167,7 @@ # delete-next-word=Mod1+d Control+Delete # extend-to-word-boundary=Control+w # extend-to-next-whitespace=Control+Shift+w +# extend-to-end-line=Control+l # clipboard-paste=Control+v Control+Shift+v Control+y XF86Paste # primary-paste=Shift+Insert diff --git a/key-binding.h b/key-binding.h index 1c0e2a99..d4bb9f51 100644 --- a/key-binding.h +++ b/key-binding.h @@ -70,6 +70,7 @@ enum bind_action_search { BIND_ACTION_SEARCH_DELETE_NEXT_WORD, BIND_ACTION_SEARCH_EXTEND_WORD, BIND_ACTION_SEARCH_EXTEND_WORD_WS, + BIND_ACTION_SEARCH_EXTEND_LINE, BIND_ACTION_SEARCH_CLIPBOARD_PASTE, BIND_ACTION_SEARCH_PRIMARY_PASTE, BIND_ACTION_SEARCH_COUNT, diff --git a/search.c b/search.c index f6d377ea..d8f1abb0 100644 --- a/search.c +++ b/search.c @@ -643,7 +643,7 @@ search_add_chars(struct terminal *term, const char *src, size_t count) } static void -search_match_to_end_of_word(struct terminal *term, bool spaces_only) +search_match_to_end_of_object(struct terminal *term, bool spaces_only, bool line) { if (term->search.match_len == 0) return; @@ -683,10 +683,14 @@ search_match_to_end_of_word(struct terminal *term, bool spaces_only) xassert(new_end.row < grid->num_rows); xassert(grid->rows[new_end.row] != NULL); - /* Find next word boundary */ + /* Find next word/line boundary */ new_end.row -= grid->view + grid->num_rows; new_end.row &= grid->num_rows - 1; - selection_find_word_boundary_right(term, &new_end, spaces_only, false); + if (!line) { + selection_find_word_boundary_right(term, &new_end, spaces_only, false); + } else { + selection_find_line_boundary_right(term, &new_end); + } new_end.row += grid->view; new_end.row &= grid->num_rows - 1; @@ -967,13 +971,19 @@ execute_binding(struct seat *seat, struct terminal *term, } case BIND_ACTION_SEARCH_EXTEND_WORD: - search_match_to_end_of_word(term, false); + search_match_to_end_of_object(term, false, false); *update_search_result = false; *redraw = true; return true; case BIND_ACTION_SEARCH_EXTEND_WORD_WS: - search_match_to_end_of_word(term, true); + search_match_to_end_of_object(term, true, false); + *update_search_result = false; + *redraw = true; + return true; + + case BIND_ACTION_SEARCH_EXTEND_LINE: + search_match_to_end_of_object(term, false, true); *update_search_result = false; *redraw = true; return true; diff --git a/selection.c b/selection.c index d4887382..2c626656 100644 --- a/selection.c +++ b/selection.c @@ -459,8 +459,7 @@ selection_find_word_boundary_right(struct terminal *term, struct coord *pos, } void -selection_find_line_boundary_left(struct terminal *term, struct coord *pos, - bool spaces_only) +selection_find_line_boundary_left(struct terminal *term, struct coord *pos) { int next_row = pos->row; pos->col = 0; @@ -481,8 +480,7 @@ selection_find_line_boundary_left(struct terminal *term, struct coord *pos, } void -selection_find_line_boundary_right(struct terminal *term, struct coord *pos, - bool spaces_only) +selection_find_line_boundary_right(struct terminal *term, struct coord *pos) { int next_row = pos->row; pos->col = term->cols - 1; @@ -547,8 +545,8 @@ selection_start(struct terminal *term, int col, int row, case SELECTION_LINE_WISE: { struct coord start = {0, row}, end = {term->cols - 1, row}; - selection_find_line_boundary_left(term, &start, spaces_only); - selection_find_line_boundary_right(term, &end, spaces_only); + selection_find_line_boundary_left(term, &start); + selection_find_line_boundary_right(term, &end); term->selection.coords.start = (struct coord){ start.col, term->grid->view + start.row}; @@ -889,7 +887,7 @@ selection_update(struct terminal *term, int col, int row) case SELECTION_LEFT: { struct coord end = {0, row}; selection_find_line_boundary_left( - term, &end, term->selection.spaces_only); + term, &end); new_end = (struct coord){end.col, term->grid->view + end.row}; break; } @@ -897,7 +895,7 @@ selection_update(struct terminal *term, int col, int row) case SELECTION_RIGHT: { struct coord end = {col, row}; selection_find_line_boundary_right( - term, &end, term->selection.spaces_only); + term, &end); new_end = (struct coord){end.col, term->grid->view + end.row}; break; } @@ -1040,8 +1038,8 @@ selection_extend_normal(struct terminal *term, int col, int row, struct coord pivot_start = {new_start.col, new_start.row - term->grid->view}; struct coord pivot_end = pivot_start; - selection_find_line_boundary_left(term, &pivot_start, spaces_only); - selection_find_line_boundary_right(term, &pivot_end, spaces_only); + selection_find_line_boundary_left(term, &pivot_start); + selection_find_line_boundary_right(term, &pivot_end); term->selection.pivot.start = (struct coord){pivot_start.col, term->grid->view + pivot_start.row}; diff --git a/selection.h b/selection.h index 3d0c224e..5776ac48 100644 --- a/selection.h +++ b/selection.h @@ -81,5 +81,8 @@ void selection_find_word_boundary_right( struct terminal *term, struct coord *pos, bool spaces_only, bool stop_on_space_to_word_boundary); +void selection_find_line_boundary_right( + struct terminal *term, struct coord *pos); + struct coord selection_get_start(const struct terminal *term); struct coord selection_get_end(const struct terminal *term);