WindowServer: Ensure on a menu key press invalid items are not hovered
Whenever a new menu item is hovered through a up or down key press, we should always end up hovering a valid item.
This commit is contained in:
parent
7b6d450b6a
commit
01cefa83aa
Notes:
sideshowbarker
2024-07-19 09:26:53 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/01cefa83aa1 Pull-request: https://github.com/SerenityOS/serenity/pull/1209 Reviewed-by: https://github.com/awesomekling
1 changed files with 4 additions and 4 deletions
|
@ -399,12 +399,12 @@ void Menu::event(Core::Event& event)
|
|||
do {
|
||||
if (m_hovered_item_index == 0)
|
||||
m_hovered_item_index = m_items.size() - 1;
|
||||
else if (m_hovered_item_index < 0)
|
||||
return;
|
||||
else
|
||||
--m_hovered_item_index;
|
||||
} while (hovered_item()->type() == MenuItem::Separator);
|
||||
|
||||
ASSERT(m_hovered_item_index >= 0 && m_hovered_item_index <= m_items.size() - 1);
|
||||
|
||||
if (is_scrollable() && m_hovered_item_index < m_scroll_offset)
|
||||
--m_scroll_offset;
|
||||
|
||||
|
@ -421,12 +421,12 @@ void Menu::event(Core::Event& event)
|
|||
do {
|
||||
if (m_hovered_item_index == m_items.size() - 1)
|
||||
m_hovered_item_index = 0;
|
||||
else if (m_hovered_item_index > m_items.size() - 1)
|
||||
return;
|
||||
else
|
||||
++m_hovered_item_index;
|
||||
} while (hovered_item()->type() == MenuItem::Separator);
|
||||
|
||||
ASSERT(m_hovered_item_index >= 0 && m_hovered_item_index <= m_items.size() - 1);
|
||||
|
||||
if (is_scrollable() && m_hovered_item_index >= (m_scroll_offset + visible_item_count()))
|
||||
++m_scroll_offset;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue