menu: simplified conditionals in menu_item_select_by_accelerator()

This commit is contained in:
Alex Chernika 2026-04-11 02:28:44 +02:00
parent 60a3963ba9
commit 310c15058d
No known key found for this signature in database
GPG key ID: 6029FAD8ABFB076A

View file

@ -1479,7 +1479,7 @@ menu_item_select_by_accelerator(char accelerator)
return false; return false;
} }
bool needs_exec = true; bool needs_exec = false;
bool matched = false; bool matched = false;
struct menuitem *selection = menu->selection.item; struct menuitem *selection = menu->selection.item;
@ -1490,29 +1490,32 @@ menu_item_select_by_accelerator(char accelerator)
do { do {
current = current->next; current = current->next;
item = wl_container_of(current, item, link); item = wl_container_of(current, item, link);
if (!matched && item->accelerator == accelerator) { if (item->accelerator == accelerator) {
/* Menuentry with a matching accelerator found */ if (!matched) {
next_selection = item; /* Found first match */
matched = true; next_selection = item;
} else if (matched && item->accelerator == accelerator) { needs_exec = true;
/* matched = true;
* Another menuentry with such accelerator found, } else {
* cycle selection instead of executing /*
*/ * Found another match,
needs_exec = false; * cycle selection instead of executing
break; */
needs_exec = false;
break;
}
} }
} while (current != start); } while (current != start);
if (next_selection) { if (next_selection) {
menu_process_item_selection(next_selection); menu_process_item_selection(next_selection);
if (needs_exec && next_selection->submenu) { if (needs_exec && next_selection->submenu) {
/* Since we can't execute a submenu, enter it instead. */ /* Since we can't execute a submenu, enter it. */
needs_exec = false; needs_exec = false;
menu_submenu_enter(); menu_submenu_enter();
} }
} }
return matched && needs_exec; return needs_exec;
} }
bool bool