ref: 696e3997dca6911e7c48044ef0fac24b8863680a
parent: 02b9f2ba8aabe7bf471920b497eb5741cb1daa81
author: cancel <cancel@cancel.fm>
date: Sun Jan 5 21:19:25 EST 2020
Add additional protection against bad menu cycling
--- a/term_util.c
+++ b/term_util.c
@@ -507,13 +507,17 @@
case KEY_UP: {
ITEM* starting = current_item(qm->ncurses_menu);
menu_driver(qm->ncurses_menu, REQ_UP_ITEM);
+ ITEM* cur = current_item(qm->ncurses_menu);
for (;;) {
- ITEM* cur = current_item(qm->ncurses_menu);
if (!cur || cur == starting)
break;
if (!qmenu_itemextra(extras, cur)->is_spacer)
break;
+ ITEM* prev = cur;
menu_driver(qm->ncurses_menu, REQ_UP_ITEM);
+ cur = current_item(qm->ncurses_menu);
+ if (cur == prev)
+ break;
}
return false;
}
@@ -520,13 +524,17 @@
case KEY_DOWN: {
ITEM* starting = current_item(qm->ncurses_menu);
menu_driver(qm->ncurses_menu, REQ_DOWN_ITEM);
+ ITEM* cur = current_item(qm->ncurses_menu);
for (;;) {
- ITEM* cur = current_item(qm->ncurses_menu);
if (!cur || cur == starting)
break;
if (!qmenu_itemextra(extras, cur)->is_spacer)
break;
+ ITEM* prev = cur;
menu_driver(qm->ncurses_menu, REQ_DOWN_ITEM);
+ cur = current_item(qm->ncurses_menu);
+ if (cur == prev)
+ break;
}
return false;
}