Add scroll-up/scroll-down for choose/more mode, from Micah Cowan.

This commit is contained in:
Nicholas Marriott 2010-02-01 22:15:51 +00:00
parent c29bfd2ff3
commit 06ce9da32a
4 changed files with 43 additions and 4 deletions

View File

@ -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 }

2
tmux.h
View File

@ -442,6 +442,8 @@ enum mode_key_cmd {
MODEKEYCHOICE_DOWN,
MODEKEYCHOICE_PAGEDOWN,
MODEKEYCHOICE_PAGEUP,
MODEKEYCHOICE_SCROLLDOWN,
MODEKEYCHOICE_SCROLLUP,
MODEKEYCHOICE_UP,
/* Copy keys. */

View File

@ -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)) {

View File

@ -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: