1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

WindowManager: Fix default menu item on key down

This fixes the key down behavior on Terminal's Edit menu, which tried
to hover the disabled menu item Copy if there was nothing selected.
This commit is contained in:
Jean-Baptiste Boric 2021-02-13 14:40:20 +01:00 committed by Andreas Kling
parent f8cb068354
commit e616cb35ba

View file

@ -391,9 +391,16 @@ void Menu::event(Core::Event& event)
ASSERT(menu_window());
ASSERT(menu_window()->is_visible());
// Default to the first item on key press if one has not been selected yet
// Default to the first enabled, non-separator item on key press if one has not been selected yet
if (!hovered_item()) {
m_hovered_item_index = 0;
int counter = 0;
for (const auto& item : m_items) {
if (item.type() != MenuItem::Separator && item.is_enabled()) {
m_hovered_item_index = counter;
break;
}
counter++;
}
update_for_new_hovered_item(key == Key_Right);
return;
}