From: Jeffrey Middleton Date: Tue, 3 Mar 2009 22:14:38 +0000 (+0100) Subject: list_window: added top, middle, and bottom commands X-Git-Tag: release-0.14~84 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=152e021619f3791d3c87a03a76625f3563413529;p=ncmpc.git list_window: added top, middle, and bottom commands Commands to move cursor to top, middle, and bottom of screen, mapped by default to H, M, and L like in Vim. --- diff --git a/src/command.c b/src/command.c index ad8b8d4..3a16e80 100644 --- a/src/command.c +++ b/src/command.c @@ -76,6 +76,12 @@ static command_definition_t cmds[] = { N_("Move cursor up") }, { { DWN, 'j', 0 }, 0, CMD_LIST_NEXT, "down", N_("Move cursor down") }, + { { 'H', 0, 0 }, 0, CMD_LIST_TOP, "top", + N_("Move cursor to top of screen") }, + { { 'M', 0, 0 }, 0, CMD_LIST_MIDDLE, "middle", + N_("Move cursor to middle of screen") }, + { { 'L', 0, 0 }, 0, CMD_LIST_BOTTOM, "bottom", + N_("Move cursor to bottom of screen") }, { { HOME, 0x01, 0 }, 0, CMD_LIST_FIRST, "home", N_("Home") }, { { END, 0x05, 0 }, 0, CMD_LIST_LAST, "end", diff --git a/src/command.h b/src/command.h index 7111a2b..c7514c4 100644 --- a/src/command.h +++ b/src/command.h @@ -59,6 +59,9 @@ typedef enum { CMD_SEARCH_MODE, CMD_LIST_PREVIOUS, CMD_LIST_NEXT, + CMD_LIST_TOP, + CMD_LIST_MIDDLE, + CMD_LIST_BOTTOM, CMD_LIST_FIRST, CMD_LIST_LAST, CMD_LIST_NEXT_PAGE, diff --git a/src/list_window.c b/src/list_window.c index 17107d6..bf0f45a 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -152,6 +152,30 @@ list_window_previous(struct list_window *lw, unsigned length) list_window_set_selected(lw, length-1); } +static void +list_window_top(struct list_window *lw) +{ + list_window_set_selected(lw, lw->start); +} + +static void +list_window_middle(struct list_window *lw, unsigned length) +{ + if (length >= lw->rows) + list_window_set_selected(lw, lw->start + lw->rows / 2); + else + list_window_set_selected(lw, length / 2); +} + +static void +list_window_bottom(struct list_window *lw, unsigned length) +{ + if (length >= lw->rows) + list_window_set_selected(lw, lw->start + lw->rows - 1); + else + list_window_set_selected(lw, length - 1); +} + static void list_window_first(struct list_window *lw) { @@ -369,6 +393,15 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd) case CMD_LIST_NEXT: list_window_next(lw, rows); break; + case CMD_LIST_TOP: + list_window_top(lw); + break; + case CMD_LIST_MIDDLE: + list_window_middle(lw,rows); + break; + case CMD_LIST_BOTTOM: + list_window_bottom(lw,rows); + break; case CMD_LIST_FIRST: list_window_first(lw); break; diff --git a/src/screen_help.c b/src/screen_help.c index f8438dc..5a0654f 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -39,6 +39,9 @@ static help_text_row_t help_text[] = { { 2, CMD_NONE, NULL }, { 0, CMD_LIST_PREVIOUS, NULL }, { 0, CMD_LIST_NEXT, NULL }, + { 0, CMD_LIST_TOP, NULL }, + { 0, CMD_LIST_MIDDLE, NULL }, + { 0, CMD_LIST_BOTTOM, NULL }, { 0, CMD_LIST_PREVIOUS_PAGE, NULL }, { 0, CMD_LIST_NEXT_PAGE, NULL }, { 0, CMD_LIST_FIRST, NULL },