diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-01-28 20:20:34 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-01-29 10:42:26 +0100 |
commit | 3dea3e9b4a6a658a02c2547dcea15e320e62efaf (patch) | |
tree | 946c73bcea55627faf21b9eb250ceee8943ad2e5 | |
parent | 6c1a55b8df82c8568e9d00f7968e6e057077b109 (diff) |
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>
-rw-r--r-- | vcl/source/window/menuitemlist.cxx | 36 |
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; |