summaryrefslogtreecommitdiff
path: root/vcl/source/window/menuitemlist.cxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-01-28 20:20:34 +0000
committerCaolán McNamara <caolanm@redhat.com>2020-01-29 09:50:37 +0100
commitab20238ad175e027ccfe4532c3899454837253b9 (patch)
tree897932c551f40b875def588e9542b5c3b894ccbd /vcl/source/window/menuitemlist.cxx
parent6d6e80435fd7f71342c429a67759a7b7b280cc55 (diff)
Resolves: tdf#130130 Insert menu, multiple hotkey never reaches 3rd item
Change-Id: Ica70be71094229a12c16eee1d3ff6960b7e06734 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87657 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source/window/menuitemlist.cxx')
-rw-r--r--vcl/source/window/menuitemlist.cxx36
1 files changed, 30 insertions, 6 deletions
diff --git a/vcl/source/window/menuitemlist.cxx b/vcl/source/window/menuitemlist.cxx
index 7e55f0c3ed32..6921e6208118 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;