From: nicm Date: Tue, 23 Aug 2022 08:14:19 +0000 (+0000) Subject: Add scroll-middle copy mode command to make cursor line in the middle, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=32e9379bfd22bde6ec4810c2c45e3dcb7733c622;p=openbsd Add scroll-middle copy mode command to make cursor line in the middle, from Varun Kumar E in GitHub issue 3307. --- diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c index 2e23549d238..adadb4ee7f1 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.145 2022/08/15 08:41:13 nicm Exp $ */ +/* $OpenBSD: key-bindings.c,v 1.146 2022/08/23 08:14:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -605,6 +605,7 @@ key_bindings_init(void) "bind -Tcopy-mode-vi h { send -X cursor-left }", "bind -Tcopy-mode-vi j { send -X cursor-down }", "bind -Tcopy-mode-vi k { send -X cursor-up }", + "bind -Tcopy-mode-vi z { send -X scroll-middle }", "bind -Tcopy-mode-vi l { send -X cursor-right }", "bind -Tcopy-mode-vi n { send -X search-again }", "bind -Tcopy-mode-vi o { send -X other-end }", diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index e668225ccdf..35dd362bdfa 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.899 2022/08/15 09:10:34 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.900 2022/08/23 08:14:19 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 15 2022 $ +.Dd $Mdocdate: August 23 2022 $ .Dt TMUX 1 .Os .Sh NAME @@ -1808,6 +1808,7 @@ The following commands are supported in copy mode: .It Li "search-forward " Ta "/" Ta "" .It Li "search-forward-incremental " Ta "" Ta "C-s" .It Li "search-forward-text " Ta "" Ta "" +.It Li "scroll-middle" Ta "z" Ta "" .It Li "search-reverse" Ta "N" Ta "N" .It Li "select-line" Ta "V" Ta "" .It Li "select-word" Ta "" Ta "" diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index f6bb56f2b09..56551d24430 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.338 2022/08/03 13:27:48 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.339 2022/08/23 08:14:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1250,6 +1250,32 @@ window_copy_cmd_cursor_right(struct window_copy_cmd_state *cs) return (WINDOW_COPY_CMD_NOTHING); } +static enum window_copy_cmd_action +window_copy_cmd_scroll_middle(struct window_copy_cmd_state *cs) +{ + struct window_mode_entry *wme = cs->wme; + struct window_copy_mode_data *data = wme->data; + u_int mid_value, oy, delta; + int scroll_up; /* >0 up, <0 down */ + + mid_value = (screen_size_y(&data->screen) - 1) / 2; + scroll_up = data->cy - mid_value; + delta = abs(scroll_up); + oy = screen_hsize(data->backing) + data->cy - data->oy; + + log_debug ("XXX %u %u %u %d %u", mid_value, oy, delta, scroll_up, data->oy); + if (scroll_up > 0 && data->oy >= delta) { + window_copy_scroll_up(wme, delta); + data->cy -= delta; + } else if (scroll_up < 0 && oy >= delta) { + window_copy_scroll_down(wme, delta); + data->cy += delta; + } + + window_copy_update_selection(wme, 0, 0); + return (WINDOW_COPY_CMD_REDRAW); +} + static enum window_copy_cmd_action window_copy_cmd_cursor_up(struct window_copy_cmd_state *cs) { @@ -2780,6 +2806,12 @@ static const struct { .clear = WINDOW_COPY_CMD_CLEAR_ALWAYS, .f = window_copy_cmd_scroll_down_and_cancel }, + { .command = "scroll-middle", + .minargs = 0, + .maxargs = 0, + .clear = WINDOW_COPY_CMD_CLEAR_ALWAYS, + .f = window_copy_cmd_scroll_middle + }, { .command = "scroll-up", .minargs = 0, .maxargs = 0,