Add keys to scroll to next/prev browseable entry - sacc - sacc(omys), simple co… | |
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
LICENSE | |
--- | |
commit 90277d09e34282cbd7c21fbc6b0f5190aca3df21 | |
parent 38704075332efd50523896ea0ae68275b7fe0a0f | |
Author: Quentin Rameau <[email protected]> | |
Date: Fri, 1 Sep 2017 16:09:47 +0200 | |
Add keys to scroll to next/prev browseable entry | |
Diffstat: | |
M config.def.h | 2 ++ | |
M ui_ti.c | 25 +++++++++++++++++++++++++ | |
2 files changed, 27 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/config.def.h b/config.def.h | |
@@ -2,7 +2,9 @@ | |
/* Screen UI navigation keys */ | |
#define _key_lndown 'j' /* move one line down */ | |
+#define _key_entrydown 'J' /* move to next link */ | |
#define _key_lnup 'k' /* move one line up */ | |
+#define _key_entryup 'K' /* move to next link */ | |
#define _key_pgdown ' ' /* move one screen down */ | |
#define _key_pgup 'b' /* move one screen up */ | |
#define _key_home 'g' /* move to the top of page */ | |
diff --git a/ui_ti.c b/ui_ti.c | |
@@ -334,6 +334,25 @@ jumptoline(Item *entry, ssize_t line, int absolute) | |
return; | |
} | |
+static ssize_t | |
+nearentry(Item *entry, int direction) | |
+{ | |
+ Dir *dir = entry->dat; | |
+ size_t item, lastitem; | |
+ | |
+ if (!dir) | |
+ return -1; | |
+ lastitem = dir->nitems; | |
+ item = dir->curline + direction; | |
+ | |
+ for (; item >= 0 && item < lastitem; item += direction) { | |
+ if (dir->items[item]->type != 'i') | |
+ return item; | |
+ } | |
+ | |
+ return dir->curline; | |
+} | |
+ | |
Item * | |
uiselectitem(Item *entry) | |
{ | |
@@ -394,6 +413,9 @@ uiselectitem(Item *entry) | |
lndown: | |
movecurline(entry, 1); | |
continue; | |
+ case _key_entrydown: | |
+ jumptoline(entry, nearentry(entry, 1), 1); | |
+ continue; | |
case _key_pgdown: | |
pgdown: | |
jumptoline(entry, dir->printoff + plines, 0); | |
@@ -406,6 +428,9 @@ uiselectitem(Item *entry) | |
lnup: | |
movecurline(entry, -1); | |
continue; | |
+ case _key_entryup: | |
+ jumptoline(entry, nearentry(entry, -1), 1); | |
+ continue; | |
case _key_pgup: | |
pgup: | |
jumptoline(entry, dir->printoff - plines, 0); |