From: Jeffrey Middleton Date: Thu, 5 Mar 2009 22:43:02 +0000 (-0600) Subject: list_window: Added scroll up/down commands X-Git-Tag: release-0.14~82 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=01694c3c217403471136792b0730fdd2263ea8ea;p=ncmpc.git list_window: Added scroll up/down commands Commands scroll a list window up/down by one line, mapped by default to Ctrl-N and Ctrl-B (mnemonics next and back). The scrolling functions can scroll by an arbitrary amount, so we can use them later for half-screen scroll commands like Vim's Ctrl-D/U. --- diff --git a/src/command.c b/src/command.c index 3a16e80..7182d16 100644 --- a/src/command.c +++ b/src/command.c @@ -92,6 +92,10 @@ static command_definition_t cmds[] = { N_("Page down") }, { { 'v', 0, 0 }, 0, CMD_LIST_VISUAL_SELECT, "visual-select", N_("Visual selection") }, + { { 14, 0, 0 }, 0, CMD_LIST_SCROLL_DOWN_LINE, "scroll-down-line", + N_("Scroll up one line") }, + { { 2, 0, 0 }, 0, CMD_LIST_SCROLL_UP_LINE, "scroll-up-line", + N_("Scroll down one line") }, /* basic screens */ diff --git a/src/command.h b/src/command.h index c7514c4..abfca44 100644 --- a/src/command.h +++ b/src/command.h @@ -74,6 +74,8 @@ typedef enum { CMD_LIST_MOVE_UP, CMD_LIST_MOVE_DOWN, CMD_LIST_VISUAL_SELECT, + CMD_LIST_SCROLL_UP_LINE, + CMD_LIST_SCROLL_DOWN_LINE, CMD_MOUSE_EVENT, CMD_SCREEN_UPDATE, CMD_SCREEN_PREVIOUS, diff --git a/src/list_window.c b/src/list_window.c index 8d1a2d5..a127a5b 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -221,6 +221,56 @@ list_window_previous_page(struct list_window *lw) list_window_first(lw); } +static void +list_window_scroll_up(struct list_window *lw, unsigned n) +{ + if (lw->start > 0) { + if (n > lw->start) + lw->start = 0; + else + lw->start -= n; + if (lw->selected > lw->start + lw->rows - 1) { + lw->selected = lw->start + lw->rows - 1; + if (lw->visual_selection) { + if (lw->selected < lw->visual_base) { + lw->selected_start = lw->selected; + lw->selected_end = lw->visual_base; + } else { + lw->selected_end = lw->selected; + } + } else { + lw->selected_start = lw->selected; + lw->selected_end = lw->selected; + } + } + } +} + +static void +list_window_scroll_down(struct list_window *lw, unsigned length, unsigned n) +{ + if (lw->start + lw->rows < length - 1) + { + if ( lw->start + lw->rows + n > length - 1) + lw->start = length-1; + else + lw->start += n; + if (lw->selected < lw->start) { + lw->selected = lw->start; + if (lw->visual_selection) { + if (lw->selected > lw->visual_base) { + lw->selected_end = lw->selected; + lw->selected_start = lw->visual_base; + } else { + lw->selected_start = lw->selected; + } + } else { + lw->selected_start = lw->selected; + lw->selected_end = lw->selected; + } + } + } +} void list_window_paint(struct list_window *lw, @@ -434,6 +484,12 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd) lw->visual_selection = true; } break; + case CMD_LIST_SCROLL_UP_LINE: + list_window_scroll_up(lw, 1); + break; + case CMD_LIST_SCROLL_DOWN_LINE: + list_window_scroll_down(lw, rows, 1); + break; default: return false; } diff --git a/src/screen_help.c b/src/screen_help.c index 5a0654f..e731664 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -47,6 +47,8 @@ static help_text_row_t help_text[] = { { 0, CMD_LIST_FIRST, NULL }, { 0, CMD_LIST_LAST, NULL }, { 0, CMD_LIST_VISUAL_SELECT, NULL }, + { 0, CMD_LIST_SCROLL_UP_LINE, NULL}, + { 0, CMD_LIST_SCROLL_DOWN_LINE, NULL}, { 0, CMD_NONE, NULL }, { 0, CMD_SCREEN_PREVIOUS,NULL }, { 0, CMD_SCREEN_NEXT, NULL },