mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +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());
|
||||||
VERIFY(menu_window()->is_visible());
|
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()) {
|
if (!hovered_item()) {
|
||||||
int counter = 0;
|
if (key == Key_Up) {
|
||||||
for (const auto& item : m_items) {
|
// Default to the last enabled, non-separator item on key press if one has not been selected yet
|
||||||
if (item.type() != MenuItem::Separator && item.is_enabled()) {
|
for (auto i = static_cast<int>(m_items.size()) - 1; i >= 0; i--) {
|
||||||
set_hovered_index(counter, key == Key_Right);
|
auto& item = m_items.at(i);
|
||||||
break;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue