From: nicm Date: Mon, 9 Aug 2021 13:08:08 +0000 (+0000) Subject: Change copy-line and copy-end-of-line not to cancel and add -and-cancel X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5d5402dcaa148713dd01934d16b2463627d3dd54;p=openbsd Change copy-line and copy-end-of-line not to cancel and add -and-cancel variants, like the other copy commands. GitHub issue 2799. --- diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c index 24e512b5604..f8ebc15ed37 100644 --- a/usr.bin/tmux/key-bindings.c +++ b/usr.bin/tmux/key-bindings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-bindings.c,v 1.135 2021/06/10 07:52:56 nicm Exp $ */ +/* $OpenBSD: key-bindings.c,v 1.136 2021/08/09 13:08:08 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -476,7 +476,7 @@ key_bindings_init(void) "bind -Tcopy-mode C-f send -X cursor-right", "bind -Tcopy-mode C-b send -X cursor-left", "bind -Tcopy-mode C-g send -X clear-selection", - "bind -Tcopy-mode C-k send -X copy-end-of-line", + "bind -Tcopy-mode C-k send -X copy-end-of-line-and-cancel", "bind -Tcopy-mode C-n send -X cursor-down", "bind -Tcopy-mode C-p send -X cursor-up", "bind -Tcopy-mode C-r command-prompt -T search -ip'(search up)' -I'#{pane_search_string}' 'send -X search-backward-incremental \"%%%\"'", @@ -575,7 +575,7 @@ key_bindings_init(void) "bind -Tcopy-mode-vi ? command-prompt -T search -p'(search up)' 'send -X search-backward \"%%%\"'", "bind -Tcopy-mode-vi A send -X append-selection-and-cancel", "bind -Tcopy-mode-vi B send -X previous-space", - "bind -Tcopy-mode-vi D send -X copy-end-of-line", + "bind -Tcopy-mode-vi D send -X copy-end-of-line-and-cancel", "bind -Tcopy-mode-vi E send -X next-space-end", "bind -Tcopy-mode-vi F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'", "bind -Tcopy-mode-vi G send -X history-bottom", diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 3f55b5a8573..9854e85fd07 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.846 2021/08/06 09:19:02 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.847 2021/08/09 13:08:08 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: August 6 2021 $ +.Dd $Mdocdate: August 9 2021 $ .Dt TMUX 1 .Os .Sh NAME @@ -1676,8 +1676,10 @@ The following commands are supported in copy mode: .It Li "bottom-line" Ta "L" Ta "" .It Li "cancel" Ta "q" Ta "Escape" .It Li "clear-selection" Ta "Escape" Ta "C-g" -.It Li "copy-end-of-line []" Ta "D" Ta "C-k" +.It Li "copy-end-of-line []" Ta "" Ta "" +.It Li "copy-end-of-line-and-cancel []" Ta "D" Ta "C-k" .It Li "copy-line []" Ta "" Ta "" +.It Li "copy-line-and-cancel []" Ta "" Ta "" .It Li "copy-pipe [] []" Ta "" Ta "" .It Li "copy-pipe-no-clear [] []" Ta "" Ta "" .It Li "copy-pipe-and-cancel [] []" Ta "" Ta "" diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 73d3204b130..3c2a5de94d8 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.324 2021/06/10 07:58:42 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.325 2021/08/09 13:08:08 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -960,6 +960,42 @@ window_copy_cmd_clear_selection(struct window_copy_cmd_state *cs) static enum window_copy_cmd_action window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct session *s = cs->s; + struct winlink *wl = cs->wl; + struct window_pane *wp = wme->wp; + u_int np = wme->prefix, ocx, ocy, ooy; + struct window_copy_mode_data *data = wme->data; + char *prefix = NULL; + + if (cs->args->argc == 2) + prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp); + + ocx = data->cx; + ocy = data->cy; + ooy = data->oy; + + window_copy_start_selection(wme); + for (; np > 1; np--) + window_copy_cursor_down(wme, 0); + window_copy_cursor_end_of_line(wme); + + if (s != NULL) + window_copy_copy_selection(wme, prefix); + window_copy_clear_selection(wme); + + data->cx = ocx; + data->cy = ocy; + data->oy = ooy; + + free(prefix); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_end_of_line_and_cancel(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; struct client *c = cs->c; @@ -990,6 +1026,44 @@ window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs) static enum window_copy_cmd_action window_copy_cmd_copy_line(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct client *c = cs->c; + struct session *s = cs->s; + struct winlink *wl = cs->wl; + struct window_pane *wp = wme->wp; + struct window_copy_mode_data *data = wme->data; + u_int np = wme->prefix, ocx, ocy, ooy; + char *prefix = NULL; + + if (cs->args->argc == 2) + prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp); + + ocx = data->cx; + ocy = data->cy; + ooy = data->oy; + + data->selflag = SEL_CHAR; + window_copy_cursor_start_of_line(wme); + window_copy_start_selection(wme); + for (; np > 1; np--) + window_copy_cursor_down(wme, 0); + window_copy_cursor_end_of_line(wme); + + if (s != NULL) + window_copy_copy_selection(wme, prefix); + window_copy_clear_selection(wme); + + data->cx = ocx; + data->cy = ocy; + data->oy = ooy; + + free(prefix); + return (WINDOW_COPY_CMD_REDRAW); +} + +static enum window_copy_cmd_action +window_copy_cmd_copy_line_and_cancel(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; struct client *c = cs->c; @@ -2264,8 +2338,12 @@ static const struct { window_copy_cmd_clear_selection }, { "copy-end-of-line", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS, window_copy_cmd_copy_end_of_line }, + { "copy-end-of-line-and-cancel", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS, + window_copy_cmd_copy_end_of_line_and_cancel }, { "copy-line", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS, window_copy_cmd_copy_line }, + { "copy-line-and-cancel", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS, + window_copy_cmd_copy_line_and_cancel }, { "copy-pipe-no-clear", 0, 2, WINDOW_COPY_CMD_CLEAR_NEVER, window_copy_cmd_copy_pipe_no_clear }, { "copy-pipe", 0, 2, WINDOW_COPY_CMD_CLEAR_ALWAYS,