From 32291172bf00770c2b5405cf43cac33ed4ec8410 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Tue, 6 Oct 2009 14:10:10 +0000 Subject: [PATCH] Sync OpenBSD patchset 361: Make C-Up and C-Down in copy mode scroll the screen up and down one line without moving the cursor, like Up and Down in scroll mode (which will shortly disappear). --- mode-key.c | 8 +++++++- tmux.1 | 6 ++++-- tmux.h | 4 +++- window-copy.c | 40 +++++++++++++++++++++++++--------------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/mode-key.c b/mode-key.c index 97f33e66..54100b72 100644 --- a/mode-key.c +++ b/mode-key.c @@ -1,4 +1,4 @@ -/* $Id: mode-key.c,v 1.31 2009-10-05 18:25:05 tcunha Exp $ */ +/* $Id: mode-key.c,v 1.32 2009-10-06 14:10:10 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -89,6 +89,8 @@ struct mode_key_cmdstr mode_key_cmdstr_copy[] = { { MODEKEYCOPY_PREVIOUSPAGE, "page-up" }, { MODEKEYCOPY_PREVIOUSWORD, "previous-word" }, { MODEKEYCOPY_RIGHT, "cursor-right" }, + { MODEKEYCOPY_SCROLLDOWN, "scroll-down" }, + { MODEKEYCOPY_SCROLLUP, "scroll-up" }, { MODEKEYCOPY_SEARCHAGAIN, "search-again" }, { MODEKEYCOPY_SEARCHDOWN, "search-forward" }, { MODEKEYCOPY_SEARCHUP, "search-backward" }, @@ -177,11 +179,13 @@ const struct mode_key_entry mode_key_vi_copy[] = { { 'q', 0, MODEKEYCOPY_CANCEL }, { 'w', 0, MODEKEYCOPY_NEXTWORD }, { KEYC_BSPACE, 0, MODEKEYCOPY_LEFT }, + { KEYC_DOWN | KEYC_CTRL,0, MODEKEYCOPY_SCROLLDOWN }, { KEYC_DOWN, 0, MODEKEYCOPY_DOWN }, { KEYC_LEFT, 0, MODEKEYCOPY_LEFT }, { KEYC_NPAGE, 0, MODEKEYCOPY_NEXTPAGE }, { KEYC_PPAGE, 0, MODEKEYCOPY_PREVIOUSPAGE }, { KEYC_RIGHT, 0, MODEKEYCOPY_RIGHT }, + { KEYC_UP | KEYC_CTRL, 0, MODEKEYCOPY_SCROLLUP }, { KEYC_UP, 0, MODEKEYCOPY_UP }, { 0, -1, 0 } @@ -262,12 +266,14 @@ const struct mode_key_entry mode_key_emacs_copy[] = { { 'q', 0, MODEKEYCOPY_CANCEL }, { 'v' | KEYC_ESCAPE, 0, MODEKEYCOPY_PREVIOUSPAGE }, { 'w' | KEYC_ESCAPE, 0, MODEKEYCOPY_COPYSELECTION }, + { KEYC_DOWN | KEYC_CTRL,0, MODEKEYCOPY_SCROLLDOWN }, { KEYC_DOWN | KEYC_ESCAPE, 0, MODEKEYCOPY_HALFPAGEDOWN }, { KEYC_DOWN, 0, MODEKEYCOPY_DOWN }, { KEYC_LEFT, 0, MODEKEYCOPY_LEFT }, { KEYC_NPAGE, 0, MODEKEYCOPY_NEXTPAGE }, { KEYC_PPAGE, 0, MODEKEYCOPY_PREVIOUSPAGE }, { KEYC_RIGHT, 0, MODEKEYCOPY_RIGHT }, + { KEYC_UP | KEYC_CTRL, 0, MODEKEYCOPY_SCROLLUP }, { KEYC_UP | KEYC_ESCAPE, 0, MODEKEYCOPY_HALFPAGEUP }, { KEYC_UP, 0, MODEKEYCOPY_UP }, diff --git a/tmux.1 b/tmux.1 index fa847e6d..e52a418e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.177 2009-10-05 18:26:00 tcunha Exp $ +.\" $Id: tmux.1,v 1.178 2009-10-06 14:10:10 tcunha 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: October 4 2009 $ +.Dd $Mdocdate: October 6 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -515,6 +515,8 @@ The following keys are supported as appropriate for the mode: .It Li "Previous page" Ta "C-u" Ta "Page up" .It Li "Previous word" Ta "b" Ta "M-b" .It Li "Quit mode" Ta "q" Ta "Escape" +.It Li "Scroll down" Ta "C-Down" Ta "C-Down" +.It Li "Scroll up" Ta "C-Up" Ta "C-Up" .It Li "Search again" Ta "n" Ta "n" .It Li "Search backward" Ta "?" Ta "C-r" .It Li "Search forward" Ta "/" Ta "C-s" diff --git a/tmux.h b/tmux.h index cd69ba7d..043e4069 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.457 2009-10-06 14:00:50 tcunha Exp $ */ +/* $Id: tmux.h,v 1.458 2009-10-06 14:10:10 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -400,6 +400,8 @@ enum mode_key_cmd { MODEKEYCOPY_PREVIOUSPAGE, MODEKEYCOPY_PREVIOUSWORD, MODEKEYCOPY_RIGHT, + MODEKEYCOPY_SCROLLDOWN, + MODEKEYCOPY_SCROLLUP, MODEKEYCOPY_SEARCHAGAIN, MODEKEYCOPY_SEARCHDOWN, MODEKEYCOPY_SEARCHUP, diff --git a/window-copy.c b/window-copy.c index e5d4bc86..66273d45 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.86 2009-09-11 14:13:52 tcunha Exp $ */ +/* $Id: window-copy.c,v 1.87 2009-10-06 14:10:10 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -61,8 +61,8 @@ void window_copy_cursor_back_to_indentation(struct window_pane *); void window_copy_cursor_end_of_line(struct window_pane *); void window_copy_cursor_left(struct window_pane *); void window_copy_cursor_right(struct window_pane *); -void window_copy_cursor_up(struct window_pane *); -void window_copy_cursor_down(struct window_pane *); +void window_copy_cursor_up(struct window_pane *, int); +void window_copy_cursor_down(struct window_pane *, int); void window_copy_cursor_next_word(struct window_pane *); void window_copy_cursor_previous_word(struct window_pane *); void window_copy_scroll_up(struct window_pane *, u_int); @@ -235,11 +235,17 @@ window_copy_key(struct window_pane *wp, struct client *c, int key) window_copy_cursor_right(wp); return; case MODEKEYCOPY_UP: - window_copy_cursor_up(wp); + window_copy_cursor_up(wp, 0); return; case MODEKEYCOPY_DOWN: - window_copy_cursor_down(wp); + window_copy_cursor_down(wp, 0); return; + case MODEKEYCOPY_SCROLLUP: + window_copy_cursor_up(wp, 1); + break; + case MODEKEYCOPY_SCROLLDOWN: + window_copy_cursor_down(wp, 1); + break; case MODEKEYCOPY_PREVIOUSPAGE: window_copy_pageup(wp); break; @@ -1020,7 +1026,7 @@ window_copy_cursor_left(struct window_pane *wp) struct window_copy_mode_data *data = wp->modedata; if (data->cx == 0) { - window_copy_cursor_up(wp); + window_copy_cursor_up(wp, 0); window_copy_cursor_end_of_line(wp); } else { window_copy_update_cursor(wp, data->cx - 1, data->cy); @@ -1040,7 +1046,7 @@ window_copy_cursor_right(struct window_pane *wp) if (data->cx >= px) { window_copy_cursor_start_of_line(wp); - window_copy_cursor_down(wp); + window_copy_cursor_down(wp, 0); } else { window_copy_update_cursor(wp, data->cx + 1, data->cy); if (window_copy_update_selection(wp)) @@ -1049,7 +1055,7 @@ window_copy_cursor_right(struct window_pane *wp) } void -window_copy_cursor_up(struct window_pane *wp) +window_copy_cursor_up(struct window_pane *wp, int scroll_only) { struct window_copy_mode_data *data = wp->modedata; u_int ox, oy, px, py; @@ -1062,9 +1068,11 @@ window_copy_cursor_up(struct window_pane *wp) } data->cx = data->lastcx; - if (data->cy == 0) + if (scroll_only || data->cy == 0) { window_copy_scroll_down(wp, 1); - else { + if (scroll_only && window_copy_update_selection(wp)) + window_copy_redraw_lines(wp, data->cy, 2); + } else { window_copy_update_cursor(wp, data->cx, data->cy - 1); if (window_copy_update_selection(wp)) window_copy_redraw_lines(wp, data->cy, 2); @@ -1077,7 +1085,7 @@ window_copy_cursor_up(struct window_pane *wp) } void -window_copy_cursor_down(struct window_pane *wp) +window_copy_cursor_down(struct window_pane *wp, int scroll_only) { struct window_copy_mode_data *data = wp->modedata; struct screen *s = &data->screen; @@ -1091,9 +1099,11 @@ window_copy_cursor_down(struct window_pane *wp) } data->cx = data->lastcx; - if (data->cy == screen_size_y(s) - 1) + if (scroll_only || data->cy == screen_size_y(s) - 1) { window_copy_scroll_up(wp, 1); - else { + if (scroll_only && window_copy_update_selection(wp)) + window_copy_redraw_lines(wp, data->cy - 1, 2); + } else { window_copy_update_cursor(wp, data->cx, data->cy + 1); if (window_copy_update_selection(wp)) window_copy_redraw_lines(wp, data->cy - 1, 2); @@ -1137,7 +1147,7 @@ window_copy_cursor_next_word(struct window_pane *wp) } px = 0; - window_copy_cursor_down(wp); + window_copy_cursor_down(wp, 0); py =screen_hsize( &wp->base) + data->cy - data->oy; @@ -1185,7 +1195,7 @@ window_copy_cursor_previous_word(struct window_pane *wp) (screen_hsize(&wp->base) == 0 || data->oy >= screen_hsize(&wp->base) - 1)) goto out; - window_copy_cursor_up(wp); + window_copy_cursor_up(wp, 0); py = screen_hsize( &wp->base) + data->cy - data->oy;