[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - vcl/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Jan 29 09:43:01 UTC 2020


 vcl/source/window/menuitemlist.cxx |   36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

New commits:
commit 3dea3e9b4a6a658a02c2547dcea15e320e62efaf
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Jan 28 20:20:34 2020 +0000
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jan 29 10:42:26 2020 +0100

    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 at collabora.com>

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;


More information about the Libreoffice-commits mailing list