From 6a4cfcde954817cfcba0bb6ffa721a9931df5e1b Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 30 Jan 2020 23:05:30 -0500 Subject: [PATCH] selector: always rotate options #302 --- src/lib/selector.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/selector.c b/src/lib/selector.c index 9679eb9b2..1f6b44b3e 100644 --- a/src/lib/selector.c +++ b/src/lib/selector.c @@ -234,7 +234,7 @@ char* ncselector_selected(const ncselector* n){ } void ncselector_previtem(ncselector* n, char** newitem){ - if(n->selected == n->startdisp && n->maxdisplay && n->maxdisplay < n->itemcount){ + if(n->selected == n->startdisp){ if(n->startdisp-- == 0){ n->startdisp = n->itemcount - 1; } @@ -250,14 +250,16 @@ void ncselector_previtem(ncselector* n, char** newitem){ } void ncselector_nextitem(ncselector* n, char** newitem){ - ++n->selected; - if(n->maxdisplay && n->maxdisplay < n->itemcount){ - if((n->startdisp + n->maxdisplay) % n->itemcount == (n->selected % n->itemcount)){ - if(++n->startdisp == n->itemcount){ - n->startdisp = 0; - } + unsigned lastdisp = n->startdisp; + lastdisp += n->maxdisplay && n->maxdisplay < n->itemcount ? n->maxdisplay : n->itemcount; + --lastdisp; + lastdisp %= n->itemcount; + if(lastdisp == n->selected){ + if(++n->startdisp == n->itemcount){ + n->startdisp = 0; } } + ++n->selected; if(n->selected == n->itemcount){ n->selected = 0; }