Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions modules/juce_gui_basics/menus/juce_PopupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ static bool canBeTriggered (const PopupMenu::Item& item) noexcept
&& (item.customComponent == nullptr || item.customComponent->isTriggeredAutomatically());
}

static bool canBeActivatedByKeyboard (const PopupMenu::Item& item) noexcept
{
// Unlike canBeTriggered, this includes custom components that aren't triggered
// automatically: they handle their own mouse clicks, but should still be
// possible to highlight and activate with the keyboard.
return item.isEnabled
&& item.itemID != 0
&& ! item.isSectionHeader;
}

static bool hasActiveSubMenu (const PopupMenu::Item& item) noexcept
{
return item.isEnabled
Expand Down Expand Up @@ -643,7 +653,8 @@ struct MenuWindow final : public Component
}
else if (key.isKeyCode (KeyPress::returnKey) || key.isKeyCode (KeyPress::spaceKey))
{
triggerCurrentlyHighlightedItem();
if (currentChild != nullptr && canBeActivatedByKeyboard (currentChild->item))
dismissMenu (&currentChild->item);
}
else if (key.isKeyCode (KeyPress::escapeKey))
{
Expand Down Expand Up @@ -1268,7 +1279,7 @@ struct MenuWindow final : public Component

if (auto* mic = items.getUnchecked ((start + items.size()) % items.size()))
{
if (canBeTriggered (mic->item) || hasActiveSubMenu (mic->item))
if (canBeActivatedByKeyboard (mic->item) || hasActiveSubMenu (mic->item))
{
setCurrentlyHighlightedChild (mic);
return;
Expand Down