sfx2/source/control/thumbnailview.cxx |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

New commits:
commit 3b79c7347d14756e072265b39081bc3866e1196d
Author:     Katarina Behrens <bu...@bubli.org>
AuthorDate: Fri Jan 28 18:03:58 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue Feb 1 20:39:05 2022 +0100

    tdf#122708: on GetFocus, select something also when items are filtered
    
    Previously if nothing was selected, we picked item with ID 1 to
    select/highlight. But if a filter is active, such item may not
    match the active filter (case in point: document template no. 1
    matches 'Writer templates' filter, but not 'Impress templates' one)
    
    Try harder to find an item to select by looking at the list of
    filtered items too
    
    Change-Id: I9cb053b884dc724c7a6199ec002d83024ed83976
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129117
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <bu...@bubli.org>
    (cherry picked from commit 4bb0ffa4684dada708ecdf727f4fc9f500a9bced)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129081
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sfx2/source/control/thumbnailview.cxx 
b/sfx2/source/control/thumbnailview.cxx
index 04de9a437550..217694520427 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -923,7 +923,14 @@ void ThumbnailView::GetFocus()
 
         if (nSelected == -1 && !mItemList.empty())
         {
-            SelectItem(1);
+            ThumbnailViewItem* pFirst = nullptr;
+            if (!mFilteredItemList.empty()) {
+                pFirst = mFilteredItemList[0];
+            } else {
+                pFirst = mItemList[0].get();
+            }
+
+            SelectItem(pFirst->mnId);
         }
     }
 

Reply via email to