key-binding: add bind to clear scrollback but keep current line

This commit is contained in:
Baltazár Radics 2022-04-27 21:29:06 +02:00
parent d7a4f9e99e
commit a3fc484028
7 changed files with 29 additions and 0 deletions

View file

@ -113,3 +113,17 @@ cmd_scrollback_down(struct terminal *term, int rows)
render_refresh_urls(term); render_refresh_urls(term);
render_refresh(term); render_refresh(term);
} }
void
cmd_scrollback_clear_keepcur(struct terminal *term) {
const struct coord cursor = term->grid->cursor.point;
int real_row = grid_row_absolute(term->grid, cursor.row - 1);
struct row *row;
while (row = term->grid->rows[real_row], row && !row->linebreak)
real_row = (real_row - 1) & (term->grid->num_rows - 1);
int screen_row = (real_row + 1 - term->grid->offset) & (term->grid->num_rows - 1);
term_scroll_partial(term, (struct scroll_region){0, term->rows}, screen_row);
term_cursor_to(term, cursor.row - screen_row, cursor.col);
term_erase_scrollback(term);
render_refresh(term);
}

View file

@ -4,3 +4,4 @@
void cmd_scrollback_up(struct terminal *term, int rows); void cmd_scrollback_up(struct terminal *term, int rows);
void cmd_scrollback_down(struct terminal *term, int rows); void cmd_scrollback_down(struct terminal *term, int rows);
void cmd_scrollback_clear_keepcur(struct terminal *term);

View file

@ -117,6 +117,7 @@ static const char *const binding_action_map[] = {
[BIND_ACTION_SCROLLBACK_DOWN_LINE] = "scrollback-down-line", [BIND_ACTION_SCROLLBACK_DOWN_LINE] = "scrollback-down-line",
[BIND_ACTION_SCROLLBACK_HOME] = "scrollback-home", [BIND_ACTION_SCROLLBACK_HOME] = "scrollback-home",
[BIND_ACTION_SCROLLBACK_END] = "scrollback-end", [BIND_ACTION_SCROLLBACK_END] = "scrollback-end",
[BIND_ACTION_SCROLLBACK_CLEAR_KEEPCUR] = "scrollback-clear-keepcur",
[BIND_ACTION_CLIPBOARD_COPY] = "clipboard-copy", [BIND_ACTION_CLIPBOARD_COPY] = "clipboard-copy",
[BIND_ACTION_CLIPBOARD_PASTE] = "clipboard-paste", [BIND_ACTION_CLIPBOARD_PASTE] = "clipboard-paste",
[BIND_ACTION_PRIMARY_PASTE] = "primary-paste", [BIND_ACTION_PRIMARY_PASTE] = "primary-paste",

View file

@ -1193,6 +1193,10 @@ e.g. *search-start=none*.
*scrollback-end* *scrollback-end*
Scroll to the end (bottom) of the scrollback. Default: _none_. Scroll to the end (bottom) of the scrollback. Default: _none_.
*scrollback-clear-keepcur*
Clear scrollback, keeping only the line currently being edited. Might break
applications that do not expect it. Default: _not bound_.
*clipboard-copy* *clipboard-copy*
Copies the current selection into the _clipboard_. Default: _Control+Shift+c_ Copies the current selection into the _clipboard_. Default: _Control+Shift+c_
_XF86Copy_. _XF86Copy_.

View file

@ -186,6 +186,7 @@
# scrollback-down-line=none # scrollback-down-line=none
# scrollback-home=none # scrollback-home=none
# scrollback-end=none # scrollback-end=none
# scrollback-clear-keepcur=none
# clipboard-copy=Control+Shift+c XF86Copy # clipboard-copy=Control+Shift+c XF86Copy
# clipboard-paste=Control+Shift+v XF86Paste # clipboard-paste=Control+Shift+v XF86Paste
# primary-paste=Shift+Insert # primary-paste=Shift+Insert

View file

@ -168,6 +168,13 @@ execute_binding(struct seat *seat, struct terminal *term,
} }
break; break;
case BIND_ACTION_SCROLLBACK_CLEAR_KEEPCUR:
if (term->grid == &term->normal) {
cmd_scrollback_clear_keepcur(term);
return true;
}
break;
case BIND_ACTION_CLIPBOARD_COPY: case BIND_ACTION_CLIPBOARD_COPY:
selection_to_clipboard(seat, term, serial); selection_to_clipboard(seat, term, serial);
return true; return true;

View file

@ -18,6 +18,7 @@ enum bind_action_normal {
BIND_ACTION_SCROLLBACK_DOWN_LINE, BIND_ACTION_SCROLLBACK_DOWN_LINE,
BIND_ACTION_SCROLLBACK_HOME, BIND_ACTION_SCROLLBACK_HOME,
BIND_ACTION_SCROLLBACK_END, BIND_ACTION_SCROLLBACK_END,
BIND_ACTION_SCROLLBACK_CLEAR_KEEPCUR,
BIND_ACTION_CLIPBOARD_COPY, BIND_ACTION_CLIPBOARD_COPY,
BIND_ACTION_CLIPBOARD_PASTE, BIND_ACTION_CLIPBOARD_PASTE,
BIND_ACTION_PRIMARY_PASTE, BIND_ACTION_PRIMARY_PASTE,