sw/source/uibase/inc/QuickFindPanel.hxx     |    4 +
 sw/source/uibase/sidebar/QuickFindPanel.cxx |   60 ++++++++++++++++++++--------
 2 files changed, 48 insertions(+), 16 deletions(-)

New commits:
commit 00041882939fb83f589c854ffa5a28db90f399ca
Author:     NickWingate <[email protected]>
AuthorDate: Wed Sep 10 12:50:03 2025 +0100
Commit:     Szymon Kłos <[email protected]>
CommitDate: Wed Sep 24 13:39:23 2025 +0200

    QuickFindPanel: Improve how we handle page entries
    
    We have two different 'markers' for page entries:
    '-' for desktop and '-$#~ ... ~#$-'. Minimize the
    number of places these are hard coded.
    
    Signed-off-by: NickWingate <[email protected]>
    Change-Id: I9bbffb2dca72c25bef40495152b67c7d2455917b
    (cherry picked from commit f39b12e0d2e2fd3487699ca9eaf1a7752ffb9288)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191438
    Tested-by: Szymon Kłos <[email protected]>
    Reviewed-by: Szymon Kłos <[email protected]>

diff --git a/sw/source/uibase/inc/QuickFindPanel.hxx 
b/sw/source/uibase/inc/QuickFindPanel.hxx
index 0085b31164a3..4cc129ead7f5 100644
--- a/sw/source/uibase/inc/QuickFindPanel.hxx
+++ b/sw/source/uibase/inc/QuickFindPanel.hxx
@@ -92,6 +92,10 @@ private:
 
     void NavigateSearchFinds(bool bNext);
     void FillSearchFindsList();
+    static OUString CreatePageEntry(sal_Int32 nPageNum);
+    bool IsPageEntry(const weld::TreeIter& rEntry);
+    static bool IsPageEntry(std::u16string_view sEntryId);
+    static OUString ParsePageEntry(const OUString& sEntryId);
 };
 
 class QuickFindPanelWrapper : public SfxQuickFindWrapper
diff --git a/sw/source/uibase/sidebar/QuickFindPanel.cxx 
b/sw/source/uibase/sidebar/QuickFindPanel.cxx
index d43b6bfac663..50cead0d1673 100644
--- a/sw/source/uibase/sidebar/QuickFindPanel.cxx
+++ b/sw/source/uibase/sidebar/QuickFindPanel.cxx
@@ -36,6 +36,8 @@
 #include <comphelper/lok.hxx>
 
 const int CharactersBeforeAndAfter = 40;
+const OUString LOKPageEntryPrefix = u"-$#~"_ustr;
+const OUString LOKPageEntrySuffix = u"~#$-"_ustr;
 
 namespace
 {
@@ -269,7 +271,7 @@ IMPL_LINK(QuickFindPanel, SearchFindsListMousePressHandler, 
const MouseEvent&, r
     if (std::unique_ptr<weld::TreeIter> 
xEntry(m_xSearchFindsList->make_iterator());
         m_xSearchFindsList->get_dest_row_at_pos(rMEvt.GetPosPixel(), 
xEntry.get(), false, false))
     {
-        return m_xSearchFindsList->get_id(*xEntry)[0] == '-';
+        return IsPageEntry(*xEntry);
     }
     return false;
 }
@@ -280,7 +282,7 @@ IMPL_LINK(QuickFindPanel, 
SearchFindsListCustomGetSizeHandler, weld::TreeView::g
     vcl::RenderContext& rRenderContext = std::get<0>(aPayload);
     const OUString& rId = std::get<1>(aPayload);
 
-    const bool bPageEntry = rId[0] == '-';
+    const bool bPageEntry = IsPageEntry(rId);
 
     OUString aEntry(rId);
     if (!bPageEntry)
@@ -331,7 +333,7 @@ IMPL_LINK(QuickFindPanel, SearchFindsListRender, 
weld::TreeView::render_args, aP
     const ::tools::Rectangle& rRect = std::get<1>(aPayload);
     const OUString& rId = std::get<3>(aPayload);
 
-    const bool bPageEntry = rId[0] == '-';
+    const bool bPageEntry = IsPageEntry(rId);
 
     OUString aEntry(rId);
 
@@ -377,7 +379,7 @@ IMPL_LINK(QuickFindPanel, SearchFindsListRender, 
weld::TreeView::render_args, aP
     }
     else
     {
-        aEntry = aEntry.copy(1); // remove '-'
+        aEntry = ParsePageEntry(aEntry); // remove '-' or LOKPageEntryPrefix 
and LOKPageEntrySuffix
         tools::Long aTextWidth = rRenderContext.GetTextWidth(aEntry);
         tools::Long aTextHeight = rRenderContext.GetTextHeight();
 
@@ -406,7 +408,7 @@ IMPL_LINK_NOARG(QuickFindPanel, 
SearchFindsListSelectionChangedHandler, weld::Tr
     OUString sId = m_xSearchFindsList->get_id(*xEntry);
 
     // check for page number entry
-    if (sId[0] == '-')
+    if (IsPageEntry(sId))
         return;
 
     std::unique_ptr<SwPaM>& rxPaM = m_vPaMs[sId.toUInt64()];
@@ -456,7 +458,7 @@ IMPL_LINK_NOARG(QuickFindPanel, 
SearchFindsListRowActivatedHandler, weld::TreeVi
         return false;
 
     // check for page number entry
-    if (m_xSearchFindsList->get_id(*xEntry)[0] == '-')
+    if (IsPageEntry(*xEntry))
         return false;
 
     m_pWrtShell->GetView().GetEditWin().GrabFocus();
@@ -688,16 +690,7 @@ void QuickFindPanel::FillSearchFindsList()
             if (xPaM->GetPageNum() != nPage)
             {
                 nPage = xPaM->GetPageNum();
-                OUString sPageEntry;
-                if (comphelper::LibreOfficeKit::isActive())
-                {
-                    sPageEntry = u"-$#~"_ustr + SwResId(ST_PGE) + u" "_ustr
-                                 + OUString::number(nPage) + u"~#$-"_ustr;
-                }
-                else
-                {
-                    sPageEntry = u"-"_ustr + SwResId(ST_PGE) + u" "_ustr + 
OUString::number(nPage);
-                }
+                OUString sPageEntry = CreatePageEntry(nPage);
                 m_xSearchFindsList->append(sPageEntry, sPageEntry);
             }
 
@@ -730,6 +723,41 @@ void QuickFindPanel::FillSearchFindsList()
     if (nSearchFindFoundTimes > 1)
         m_xQuickFindControls->set_visible(true);
 }
+
+OUString QuickFindPanel::CreatePageEntry(sal_Int32 nPageNum)
+{
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        return LOKPageEntryPrefix + SwResId(ST_PGE) + u" "_ustr + 
OUString::number(nPageNum)
+               + LOKPageEntrySuffix;
+    }
+    return u"-"_ustr + SwResId(ST_PGE) + u" "_ustr + 
OUString::number(nPageNum);
+}
+
+bool QuickFindPanel::IsPageEntry(const weld::TreeIter& rEntry)
+{
+    return IsPageEntry(m_xSearchFindsList->get_id(rEntry));
+}
+
+bool QuickFindPanel::IsPageEntry(std::u16string_view sEntryId)
+{
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        return sEntryId.starts_with(LOKPageEntryPrefix) && 
sEntryId.ends_with(LOKPageEntrySuffix);
+    }
+    return sEntryId[0] == '-';
+}
+
+OUString QuickFindPanel::ParsePageEntry(const OUString& sEntryId)
+{
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        return sEntryId.copy(LOKPageEntryPrefix.getLength(),
+                             sEntryId.getLength()
+                                 - LOKPageEntrySuffix.getLength()); // remove 
'-$#~' and '~#$-'
+    }
+    return sEntryId.copy(1); // remove '-'
+}
 }
 // end of namespace ::sw::sidebar
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to