Resolves: tdf#130130 Insert menu, multiple hotkey never reaches 3rd item
Change-Id: Ica70be71094229a12c16eee1d3ff6960b7e06734
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87665
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/vcl/source/window/menuitemlist.cxx b/vcl/source/window/menuitemlist.cxx
index 7e55f0c..6921e62 100644
--- a/vcl/source/window/menuitemlist.cxx
+++ b/vcl/source/window/menuitemlist.cxx
@@ -180,17 +180,29 @@ MenuItemData* MenuItemList::SearchItem(
nDuplicates = GetItemCount( cSelectChar ); // return number of duplicates
if( nDuplicates )
{
MenuItemData* pFirstMatch = nullptr;
size_t nFirstPos(0);
for ( rPos = 0; rPos < nListCount; rPos++)
{
MenuItemData* pData = maItemList[ rPos ].get();
if ( pData->bEnabled && rI18nHelper.MatchMnemonic( pData->aText, cSelectChar ) )
{
if( nDuplicates > 1 && rPos == nCurrentPos )
continue; // select next entry with the same mnemonic
else
if (nDuplicates == 1)
return pData;
if (rPos > nCurrentPos)
return pData; // select next entry with the same mnemonic
if (!pFirstMatch) // stash the first match for use if nothing follows nCurrentPos
{
pFirstMatch = pData;
nFirstPos = rPos;
}
}
}
if (pFirstMatch)
{
rPos = nFirstPos;
return pFirstMatch;
}
}
// nothing found, try keycode instead
@@ -202,6 +214,8 @@ MenuItemData* MenuItemList::SearchItem(
if( aKeyCode.GetCode() >= KEY_A && aKeyCode.GetCode() <= KEY_Z )
ascii = sal::static_int_cast<char>('A' + (aKeyCode.GetCode() - KEY_A));
MenuItemData* pFirstMatch = nullptr;
size_t nFirstPos(0);
for ( rPos = 0; rPos < nListCount; rPos++)
{
MenuItemData* pData = maItemList[ rPos ].get();
@@ -223,14 +237,24 @@ MenuItemData* MenuItemList::SearchItem(
)
)
{
if( nDuplicates > 1 && rPos == nCurrentPos )
continue; // select next entry with the same mnemonic
else
if (nDuplicates == 1)
return pData;
if (rPos > nCurrentPos)
return pData; // select next entry with the same mnemonic
if (!pFirstMatch) // stash the first match for use if nothing follows nCurrentPos
{
pFirstMatch = pData;
nFirstPos = rPos;
}
}
}
}
}
if (pFirstMatch)
{
rPos = nFirstPos;
return pFirstMatch;
}
}
return nullptr;