From c4724c7861a230e8158522a90bbed101a0ea142f Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Tue, 2 Feb 2010 23:55:21 +0000 Subject: [PATCH] Sync OpenBSD patchset 629: Add scroll-up/scroll-down for choose/more mode, from Micah Cowan. --- mode-key.c | 12 +++++++++++- tmux.h | 4 +++- window-choose.c | 35 ++++++++++++++++++++++++++++++----- window-more.c | 4 +++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/mode-key.c b/mode-key.c index 53a9f7be..50ddc8b7 100644 --- a/mode-key.c +++ b/mode-key.c @@ -1,4 +1,4 @@ -/* $Id: mode-key.c,v 1.40 2010-01-28 22:47:21 tcunha Exp $ */ +/* $Id: mode-key.c,v 1.41 2010-02-02 23:55:21 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -69,6 +69,8 @@ struct mode_key_cmdstr mode_key_cmdstr_choice[] = { { MODEKEYCHOICE_DOWN, "down" }, { MODEKEYCHOICE_PAGEDOWN, "page-down" }, { MODEKEYCHOICE_PAGEUP, "page-up" }, + { MODEKEYCHOICE_SCROLLDOWN, "scroll-down" }, + { MODEKEYCHOICE_SCROLLUP, "scroll-up" }, { MODEKEYCHOICE_UP, "up" }, { 0, NULL } @@ -145,14 +147,20 @@ struct mode_key_tree mode_key_tree_vi_edit; /* vi choice selection keys. */ const struct mode_key_entry mode_key_vi_choice[] = { + { '\002' /* C-b */, 0, MODEKEYCHOICE_PAGEUP }, { '\003' /* C-c */, 0, MODEKEYCHOICE_CANCEL }, + { '\005' /* C-e */, 0, MODEKEYCHOICE_SCROLLDOWN }, + { '\006' /* C-f */, 0, MODEKEYCHOICE_PAGEDOWN }, + { '\031' /* C-y */, 0, MODEKEYCHOICE_SCROLLUP }, { '\r', 0, MODEKEYCHOICE_CHOOSE }, { 'j', 0, MODEKEYCHOICE_DOWN }, { 'k', 0, MODEKEYCHOICE_UP }, { 'q', 0, MODEKEYCHOICE_CANCEL }, + { KEYC_DOWN | KEYC_CTRL,0, MODEKEYCHOICE_SCROLLDOWN }, { KEYC_DOWN, 0, MODEKEYCHOICE_DOWN }, { KEYC_NPAGE, 0, MODEKEYCHOICE_PAGEDOWN }, { KEYC_PPAGE, 0, MODEKEYCHOICE_PAGEUP }, + { KEYC_UP | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLUP }, { KEYC_UP, 0, MODEKEYCHOICE_UP }, { 0, -1, 0 } @@ -248,9 +256,11 @@ const struct mode_key_entry mode_key_emacs_choice[] = { { '\r', 0, MODEKEYCHOICE_CHOOSE }, { 'q', 0, MODEKEYCHOICE_CANCEL }, { 'v' | KEYC_ESCAPE, 0, MODEKEYCHOICE_PAGEUP }, + { KEYC_DOWN | KEYC_CTRL,0, MODEKEYCHOICE_SCROLLDOWN }, { KEYC_DOWN, 0, MODEKEYCHOICE_DOWN }, { KEYC_NPAGE, 0, MODEKEYCHOICE_PAGEDOWN }, { KEYC_PPAGE, 0, MODEKEYCHOICE_PAGEUP }, + { KEYC_UP | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLUP }, { KEYC_UP, 0, MODEKEYCHOICE_UP }, { 0, -1, 0 } diff --git a/tmux.h b/tmux.h index 20220158..94945fec 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.538 2010-01-28 22:45:57 tcunha Exp $ */ +/* $Id: tmux.h,v 1.539 2010-02-02 23:55:21 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -441,6 +441,8 @@ enum mode_key_cmd { MODEKEYCHOICE_DOWN, MODEKEYCHOICE_PAGEDOWN, MODEKEYCHOICE_PAGEUP, + MODEKEYCHOICE_SCROLLDOWN, + MODEKEYCHOICE_SCROLLUP, MODEKEYCHOICE_UP, /* Copy keys. */ diff --git a/window-choose.c b/window-choose.c index e77bfa75..5eee090e 100644 --- a/window-choose.c +++ b/window-choose.c @@ -1,4 +1,4 @@ -/* $Id: window-choose.c,v 1.28 2010-01-17 19:00:05 tcunha Exp $ */ +/* $Id: window-choose.c,v 1.29 2010-02-02 23:55:21 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -225,16 +225,41 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key) } data->selected++; - if (data->selected >= data->top + screen_size_y(&data->screen)) - window_choose_scroll_down(wp); - else { + if (data->selected < data->top + screen_size_y(s)) { screen_write_start(&ctx, wp, NULL); window_choose_write_line( wp, &ctx, data->selected - data->top); window_choose_write_line( wp, &ctx, data->selected - 1 - data->top); screen_write_stop(&ctx); - } + } else + window_choose_scroll_down(wp); + break; + case MODEKEYCHOICE_SCROLLUP: + if (items == 0 || data->top == 0) + break; + if (data->selected == data->top + screen_size_y(s) - 1) { + data->selected--; + window_choose_scroll_up(wp); + screen_write_start(&ctx, wp, NULL); + window_choose_write_line( + wp, &ctx, screen_size_y(s) - 1); + screen_write_stop(&ctx); + } else + window_choose_scroll_up(wp); + break; + case MODEKEYCHOICE_SCROLLDOWN: + if (items == 0 || + data->top + screen_size_y(&data->screen) >= items) + break; + if (data->selected == data->top) { + data->selected++; + window_choose_scroll_down(wp); + screen_write_start(&ctx, wp, NULL); + window_choose_write_line(wp, &ctx, 0); + screen_write_stop(&ctx); + } else + window_choose_scroll_down(wp); break; case MODEKEYCHOICE_PAGEUP: if (data->selected < screen_size_y(s)) { diff --git a/window-more.c b/window-more.c index 79095870..d1cc4c0f 100644 --- a/window-more.c +++ b/window-more.c @@ -1,4 +1,4 @@ -/* $Id: window-more.c,v 1.40 2009-12-04 22:14:47 tcunha Exp $ */ +/* $Id: window-more.c,v 1.41 2010-02-02 23:55:21 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -135,9 +135,11 @@ window_more_key(struct window_pane *wp, unused struct client *c, int key) window_pane_reset_mode(wp); break; case MODEKEYCHOICE_UP: + case MODEKEYCHOICE_SCROLLUP: window_more_scroll_up(wp); break; case MODEKEYCHOICE_DOWN: + case MODEKEYCHOICE_SCROLLDOWN: window_more_scroll_down(wp); break; case MODEKEYCHOICE_PAGEUP: