Wrap selection at the top/bottom of the list

Adds selection wrapping, such that pressing up at the top of the list
will select the last item, and pressing down at the bottom of the list
will select the first item. Additionally, cursor movement is now
exclusively handled by Left/Right and selection movement is exclusively
handled by Up/Down, as the new wrapping behavior would prevent cursor
movement from ever triggering.
This commit is contained in:
Galen Abell 2024-08-03 12:36:39 +02:00
parent 8b23811263
commit b341aaba1d

20
menu.c
View file

@ -580,26 +580,36 @@ void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state,
break;
case XKB_KEY_Left:
case XKB_KEY_KP_Left:
if (menu->cursor > 0) {
menu->cursor = nextrune(menu, -1);
render_menu(menu);
}
break;
case XKB_KEY_Up:
case XKB_KEY_KP_Up:
if (menu->sel && menu->sel->prev_match) {
menu->sel = menu->sel->prev_match;
render_menu(menu);
} else if (menu->cursor > 0) {
menu->cursor = nextrune(menu, -1);
} else if (menu->sel && menu->sel == menu->matches) {
menu->sel = menu->matches_end;
render_menu(menu);
}
break;
case XKB_KEY_Right:
case XKB_KEY_KP_Right:
case XKB_KEY_Down:
case XKB_KEY_KP_Down:
if (menu->cursor < len) {
menu->cursor = nextrune(menu, +1);
render_menu(menu);
} else if (menu->sel && menu->sel->next_match) {
}
break;
case XKB_KEY_Down:
case XKB_KEY_KP_Down:
if (menu->sel && menu->sel->next_match) {
menu->sel = menu->sel->next_match;
render_menu(menu);
} else if (menu->sel && menu->sel == menu->matches_end) {
menu->sel = menu->matches;
render_menu(menu);
}
break;
case XKB_KEY_Prior: