summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 966fff9)
raw | patch | inline | side by side (parent: 966fff9)
author | Jeffrey Middleton <jefromi@gmail.com> | |
Thu, 5 Mar 2009 22:43:02 +0000 (16:43 -0600) | ||
committer | Jeffrey Middleton <jefromi@gmail.com> | |
Thu, 5 Mar 2009 19:15:24 +0000 (13:15 -0600) |
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.
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.
src/command.c | patch | blob | history | |
src/command.h | patch | blob | history | |
src/list_window.c | patch | blob | history | |
src/screen_help.c | patch | blob | history |
diff --git a/src/command.c b/src/command.c
index 3a16e801409ffd09d8cdcc9b82472515d4335c17..7182d168689a9eef59c998676bc1eadee4e69ee1 100644 (file)
--- a/src/command.c
+++ b/src/command.c
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 c7514c421a4159eb30cd1e5f9e19d42303558c90..abfca4401ab99183bc741db7cf313be75e2985cd 100644 (file)
--- a/src/command.h
+++ b/src/command.h
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 8d1a2d577b18fbe0753e36b6f804da599ed89a1f..a127a5b07b93bdde85302d638670b488e42c6269 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
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,
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 5a0654fb3b6d3df9482a54a947d61b49db893151..e731664f66898f2ae5ecf644b6c4ff7546bddf6a 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
{ 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 },