mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
WindowServer: Select last menu item when up key pressed if no selection
When a menu is first opened and has no selected item, pressing the "up" key now selects the last menu item instead of the first.
This commit is contained in:
parent
dae2a59c77
commit
967cd6afd2
1 changed files with 18 additions and 7 deletions
|
@ -370,15 +370,26 @@ void Menu::event(Core::Event& event)
|
|||
VERIFY(menu_window());
|
||||
VERIFY(menu_window()->is_visible());
|
||||
|
||||
// Default to the first enabled, non-separator item on key press if one has not been selected yet
|
||||
if (!hovered_item()) {
|
||||
int counter = 0;
|
||||
for (const auto& item : m_items) {
|
||||
if (item.type() != MenuItem::Separator && item.is_enabled()) {
|
||||
set_hovered_index(counter, key == Key_Right);
|
||||
break;
|
||||
if (key == Key_Up) {
|
||||
// Default to the last enabled, non-separator item on key press if one has not been selected yet
|
||||
for (auto i = static_cast<int>(m_items.size()) - 1; i >= 0; i--) {
|
||||
auto& item = m_items.at(i);
|
||||
if (item.type() != MenuItem::Separator && item.is_enabled()) {
|
||||
set_hovered_index(i, key == Key_Right);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Default to the first enabled, non-separator item on key press if one has not been selected yet
|
||||
int counter = 0;
|
||||
for (const auto& item : m_items) {
|
||||
if (item.type() != MenuItem::Separator && item.is_enabled()) {
|
||||
set_hovered_index(counter, key == Key_Right);
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue