Add copy-mode -d flag to scroll a page down if in copy mode already,

from Michael Grant.
This commit is contained in:
nicm 2024-08-26 07:09:34 +00:00
parent 08be883297
commit 4823acca8f
4 changed files with 26 additions and 11 deletions

View File

@ -30,8 +30,8 @@ const struct cmd_entry cmd_copy_mode_entry = {
.name = "copy-mode",
.alias = NULL,
.args = { "eHMs:t:uq", 0, 0, NULL },
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
.args = { "deHMs:t:uq", 0, 0, NULL },
.usage = "[-deHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
.source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 },
@ -91,6 +91,8 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
}
if (args_has(args, 'u'))
window_copy_pageup(wp, 0);
if (args_has(args, 'd'))
window_copy_pagedown(wp, 0, args_has(args, 'e'));
return (CMD_RETURN_NORMAL);
}

8
tmux.1
View File

@ -2108,14 +2108,15 @@ The synopsis for the
command is:
.Bl -tag -width Ds
.It Xo Ic copy-mode
.Op Fl eHMqu
.Op Fl deHMqu
.Op Fl s Ar src-pane
.Op Fl t Ar target-pane
.Xc
Enter copy mode.
The
.Fl u
option scrolls one page up.
also scrolls one page up after entering and
.Fl d
one page down if already in copy mode.
.Fl M
begins a mouse drag (only valid if bound to a mouse key binding, see
.Sx MOUSE SUPPORT ) .
@ -2138,6 +2139,7 @@ This is intended to allow fast scrolling through a pane's history, for
example with:
.Bd -literal -offset indent
bind PageUp copy-mode -eu
bind PageDown copy-mode -ed
.Ed
.El
.Pp

1
tmux.h
View File

@ -3218,6 +3218,7 @@ void printflike(3, 4) window_copy_add(struct window_pane *, int, const char *,
void printflike(3, 0) window_copy_vadd(struct window_pane *, int, const char *,
va_list);
void window_copy_pageup(struct window_pane *, int);
void window_copy_pagedown(struct window_pane *, int, int);
void window_copy_start_drag(struct client *, struct mouse_event *);
char *window_copy_get_word(struct window_pane *, u_int, u_int);
char *window_copy_get_line(struct window_pane *, u_int);

View File

@ -41,7 +41,7 @@ static void window_copy_resize(struct window_mode_entry *, u_int, u_int);
static void window_copy_formats(struct window_mode_entry *,
struct format_tree *);
static void window_copy_pageup1(struct window_mode_entry *, int);
static int window_copy_pagedown(struct window_mode_entry *, int, int);
static int window_copy_pagedown1(struct window_mode_entry *, int, int);
static void window_copy_next_paragraph(struct window_mode_entry *);
static void window_copy_previous_paragraph(struct window_mode_entry *);
static void window_copy_redraw_selection(struct window_mode_entry *, u_int);
@ -646,8 +646,18 @@ window_copy_pageup1(struct window_mode_entry *wme, int half_page)
window_copy_redraw_screen(wme);
}
void
window_copy_pagedown(struct window_pane *wp, int half_page, int scroll_exit)
{
if (window_copy_pagedown1(TAILQ_FIRST(&wp->modes), half_page,
scroll_exit)) {
window_pane_reset_mode(wp);
return;
}
}
static int
window_copy_pagedown(struct window_mode_entry *wme, int half_page,
window_copy_pagedown1(struct window_mode_entry *wme, int half_page,
int scroll_exit)
{
struct window_copy_mode_data *data = wme->data;
@ -1347,7 +1357,7 @@ window_copy_cmd_halfpage_down(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 1, data->scroll_exit))
if (window_copy_pagedown1(wme, 1, data->scroll_exit))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);
@ -1361,7 +1371,7 @@ window_copy_cmd_halfpage_down_and_cancel(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 1, 1))
if (window_copy_pagedown1(wme, 1, 1))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);
@ -1789,7 +1799,7 @@ window_copy_cmd_page_down(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 0, data->scroll_exit))
if (window_copy_pagedown1(wme, 0, data->scroll_exit))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);
@ -1802,7 +1812,7 @@ window_copy_cmd_page_down_and_cancel(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 0, 1))
if (window_copy_pagedown1(wme, 0, 1))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);