Code

list_window: added top, middle, and bottom commands
authorJeffrey Middleton <jefromi@gmail.com>
Tue, 3 Mar 2009 22:14:38 +0000 (23:14 +0100)
committerMax Kellermann <max@duempel.org>
Tue, 3 Mar 2009 22:14:38 +0000 (23:14 +0100)
Commands to move cursor to top, middle, and bottom of screen, mapped
by default to H, M, and L like in Vim.

src/command.c
src/command.h
src/list_window.c
src/screen_help.c

index ad8b8d49322e15ba25b77539450e580a41e8ee0b..3a16e801409ffd09d8cdcc9b82472515d4335c17 100644 (file)
@@ -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",
index 7111a2b2f619f1a7bb4f2cd350d487b5a62f50f1..c7514c421a4159eb30cd1e5f9e19d42303558c90 100644 (file)
@@ -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,
index 17107d67768bbc44c15b50d4d01bf9e4815b6bfd..bf0f45aa18dd2019e6a634bf805859d31188570b 100644 (file)
@@ -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;
index f8438dccaa3f5b7b34be579c8838fef85b739bfb..5a0654fb3b6d3df9482a54a947d61b49db893151 100644 (file)
@@ -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 },