mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-30 06:52:52 +00:00
WindowServer: Cache internal Alt shortcuts on the Menu object
This way we don't have to recompute the set of shortcut keys every time we're handling an in-menu keydown event.
This commit is contained in:
parent
c2b760e335
commit
2bac9eb79d
Notes:
sideshowbarker
2024-07-18 20:37:27 +09:00
Author: https://github.com/awesomekling
Commit: 2bac9eb79d
3 changed files with 29 additions and 19 deletions
|
@ -40,6 +40,7 @@
|
|||
#include <LibGfx/Triangle.h>
|
||||
#include <WindowServer/ClientConnection.h>
|
||||
#include <WindowServer/WindowClientEndpoint.h>
|
||||
#include <ctype.h>
|
||||
|
||||
namespace WindowServer {
|
||||
|
||||
|
@ -638,4 +639,20 @@ void Menu::set_visible(bool visible)
|
|||
m_client->post_message(Messages::WindowClient::MenuVisibilityDidChange(m_menu_id, visible));
|
||||
}
|
||||
|
||||
void Menu::add_item(NonnullOwnPtr<MenuItem> item)
|
||||
{
|
||||
if (auto alt_shortcut = find_ampersand_shortcut_character(item->text())) {
|
||||
m_alt_shortcut_character_to_item_indexes.ensure(tolower(alt_shortcut)).append(m_items.size());
|
||||
}
|
||||
m_items.append(move(item));
|
||||
}
|
||||
|
||||
const Vector<size_t>* Menu::items_with_alt_shortcut(u32 alt_shortcut) const
|
||||
{
|
||||
auto it = m_alt_shortcut_character_to_item_indexes.find(tolower(alt_shortcut));
|
||||
if (it == m_alt_shortcut_character_to_item_indexes.end())
|
||||
return nullptr;
|
||||
return &it->value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue