From b341aaba1d1835da4613a2e777ea6bb5a99e41d7 Mon Sep 17 00:00:00 2001 From: Galen Abell Date: Sat, 3 Aug 2024 12:36:39 +0200 Subject: [PATCH] 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. --- menu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/menu.c b/menu.c index efd3e4a..6288c1a 100644 --- a/menu.c +++ b/menu.c @@ -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: