sw/source/uibase/inc/QuickFindPanel.hxx                 |    4 
 sw/source/uibase/sidebar/QuickFindPanel.cxx             |   53 +++++-
 sw/uiconfig/swriter/ui/sidebarquickfindoptionsdialog.ui |  122 ++++++++++------
 3 files changed, 125 insertions(+), 54 deletions(-)

New commits:
commit 1158ed2a118faa69d25f647c69089e1fb60b78b1
Author:     Vojtěch Doležal <[email protected]>
AuthorDate: Mon Jan 5 10:15:29 2026 +0100
Commit:     Jim Raykowski <[email protected]>
CommitDate: Thu Jan 15 08:02:22 2026 +0100

    tdf#170192 - Allow for Comment and RegExp search from QuickFindPanel
    
    Change-Id: I928f6397609f2f3cf8c164258a8a3d142d916ac5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196538
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <[email protected]>

diff --git a/sw/source/uibase/inc/QuickFindPanel.hxx 
b/sw/source/uibase/inc/QuickFindPanel.hxx
index 371a74079966..27346e88bdec 100644
--- a/sw/source/uibase/inc/QuickFindPanel.hxx
+++ b/sw/source/uibase/inc/QuickFindPanel.hxx
@@ -32,6 +32,8 @@ class QuickFindPanel : public PanelLayout
 
         std::unique_ptr<weld::CheckButton> m_xMatchCaseCheckButton;
         std::unique_ptr<weld::CheckButton> m_xWholeWordsOnlyCheckButton;
+        std::unique_ptr<weld::CheckButton> m_xCommentsCheckButton;
+        std::unique_ptr<weld::CheckButton> m_xRegularExpressionsCheckButton;
         std::unique_ptr<weld::CheckButton> m_xSimilarityCheckButton;
         std::unique_ptr<weld::Button> m_xSimilaritySettingsDialogButton;
 
@@ -81,6 +83,8 @@ private:
 
     bool m_bMatchCase = false;
     bool m_bWholeWordsOnly = false;
+    bool m_bComments = true;
+    bool m_bRegularExpression = false;
     bool m_bSimilarity = false;
     bool m_bIsLEVRelaxed = true;
     sal_uInt16 m_nLEVOther = 2;
diff --git a/sw/source/uibase/sidebar/QuickFindPanel.cxx 
b/sw/source/uibase/sidebar/QuickFindPanel.cxx
index 2b66453f5c54..e47bb8b21a89 100644
--- a/sw/source/uibase/sidebar/QuickFindPanel.cxx
+++ b/sw/source/uibase/sidebar/QuickFindPanel.cxx
@@ -38,6 +38,7 @@
 #include <comphelper/processfactory.hxx>
 
 const int CharactersBeforeAndAfter = 40;
+const sal_Int32 MaxShownSearchResultLength = 120;
 
 namespace
 {
@@ -66,6 +67,8 @@ 
QuickFindPanel::SearchOptionsDialog::SearchOptionsDialog(weld::Window* pParent)
                               u"SearchOptionsDialog"_ustr)
     , m_xMatchCaseCheckButton(m_xBuilder->weld_check_button(u"matchcase"_ustr))
     , 
m_xWholeWordsOnlyCheckButton(m_xBuilder->weld_check_button(u"wholewordsonly"_ustr))
+    , m_xCommentsCheckButton(m_xBuilder->weld_check_button(u"comments"_ustr))
+    , 
m_xRegularExpressionsCheckButton(m_xBuilder->weld_check_button(u"regularexpressions"_ustr))
     , 
m_xSimilarityCheckButton(m_xBuilder->weld_check_button(u"similarity"_ustr))
     , 
m_xSimilaritySettingsDialogButton(m_xBuilder->weld_button(u"similaritysettingsdialog"_ustr))
 {
@@ -204,6 +207,8 @@ IMPL_LINK_NOARG(QuickFindPanel, 
SearchOptionsToolbarClickedHandler, const OUStri
 
     aDlg.m_xMatchCaseCheckButton->set_active(m_bMatchCase);
     aDlg.m_xWholeWordsOnlyCheckButton->set_active(m_bWholeWordsOnly);
+    aDlg.m_xCommentsCheckButton->set_active(m_bComments);
+    aDlg.m_xRegularExpressionsCheckButton->set_active(m_bRegularExpression);
     aDlg.m_xSimilarityCheckButton->set_active(m_bSimilarity);
     aDlg.m_xSimilaritySettingsDialogButton->set_sensitive(m_bSimilarity);
     if (m_bSimilarity)
@@ -218,6 +223,8 @@ IMPL_LINK_NOARG(QuickFindPanel, 
SearchOptionsToolbarClickedHandler, const OUStri
     {
         m_bMatchCase = aDlg.m_xMatchCaseCheckButton->get_active();
         m_bWholeWordsOnly = aDlg.m_xWholeWordsOnlyCheckButton->get_active();
+        m_bComments = aDlg.m_xCommentsCheckButton->get_active();
+        m_bRegularExpression = 
aDlg.m_xRegularExpressionsCheckButton->get_active();
         m_bSimilarity = aDlg.m_xSimilarityCheckButton->get_active();
         if (m_bSimilarity)
         {
@@ -508,19 +515,26 @@ void QuickFindPanel::FillSearchFindsList()
     aSearchOptions.Locale = GetAppLanguageTag().getLocale();
     aSearchOptions.searchString = sFindEntry;
     aSearchOptions.replaceString.clear();
-    if (m_bWholeWordsOnly)
-        aSearchOptions.searchFlag |= css::util::SearchFlags::NORM_WORD_ONLY;
-    if (m_bSimilarity)
+    if (m_bRegularExpression)
     {
-        aSearchOptions.AlgorithmType2 = 
css::util::SearchAlgorithms2::APPROXIMATE;
-        if (m_bIsLEVRelaxed)
-            aSearchOptions.searchFlag |= css::util::SearchFlags::LEV_RELAXED;
-        aSearchOptions.changedChars = m_nLEVOther;
-        aSearchOptions.insertedChars = m_nLEVShorter;
-        aSearchOptions.deletedChars = m_nLEVLonger;
+        aSearchOptions.AlgorithmType2 = css::util::SearchAlgorithms2::REGEXP;
     }
     else
-        aSearchOptions.AlgorithmType2 = css::util::SearchAlgorithms2::ABSOLUTE;
+    {
+        if (m_bWholeWordsOnly)
+            aSearchOptions.searchFlag |= 
css::util::SearchFlags::NORM_WORD_ONLY;
+        if (m_bSimilarity)
+        {
+            aSearchOptions.AlgorithmType2 = 
css::util::SearchAlgorithms2::APPROXIMATE;
+            if (m_bIsLEVRelaxed)
+                aSearchOptions.searchFlag |= 
css::util::SearchFlags::LEV_RELAXED;
+            aSearchOptions.changedChars = m_nLEVOther;
+            aSearchOptions.insertedChars = m_nLEVShorter;
+            aSearchOptions.deletedChars = m_nLEVLonger;
+        }
+        else
+            aSearchOptions.AlgorithmType2 = 
css::util::SearchAlgorithms2::ABSOLUTE;
+    }
     TransliterationFlags nTransliterationFlags = 
TransliterationFlags::IGNORE_WIDTH;
     if (!m_bMatchCase)
         nTransliterationFlags |= TransliterationFlags::IGNORE_CASE;
@@ -528,7 +542,7 @@ void QuickFindPanel::FillSearchFindsList()
 
     m_pWrtShell->StartAllAction();
     /*sal_Int32 nFound =*/m_pWrtShell->SearchPattern(
-        aSearchOptions, false, SwDocPositions::Start, SwDocPositions::End,
+        aSearchOptions, m_bComments, SwDocPositions::Start, 
SwDocPositions::End,
         FindRanges::InBody | FindRanges::InSelAll, false);
     m_pWrtShell->EndAllAction();
 
@@ -668,8 +682,21 @@ void QuickFindPanel::FillSearchFindsList()
 
             auto nCount = nMarkIndex - nStartIndex;
             OUString sTextBeforeFind = 
OUString::Concat(sNodeText.subView(nStartIndex, nCount));
-            auto nCount1 = nPointIndex - nMarkIndex;
-            OUString sFind = OUString::Concat(sNodeText.subView(nMarkIndex, 
nCount1));
+            OUString sFind;
+            if (auto pField = SwWrtShell::GetFieldAtCursor(xPaM.get(), true);
+                pField && pField->GetTypeId() == SwFieldTypesEnum::Postit)
+            {
+                sFind += OUString::Concat("{") + 
SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT) + "}";
+            }
+            else
+            {
+                auto nCount1 = std::min(nPointIndex - nMarkIndex, 
MaxShownSearchResultLength);
+                sFind = OUString::Concat(sNodeText.subView(nMarkIndex, 
nCount1));
+                if (nPointIndex - nMarkIndex > MaxShownSearchResultLength)
+                {
+                    sFind += "...";
+                }
+            }
             auto nCount2 = nEndIndex - nPointIndex + 1;
             OUString sTextAfterFind = 
OUString::Concat(sNodeText.subView(nPointIndex, nCount2));
             OUString sStr = sTextBeforeFind + "[" + sFind + "]" + 
sTextAfterFind;
diff --git a/sw/uiconfig/swriter/ui/sidebarquickfindoptionsdialog.ui 
b/sw/uiconfig/swriter/ui/sidebarquickfindoptionsdialog.ui
index a34e841f75cb..26ebb33c9d3e 100644
--- a/sw/uiconfig/swriter/ui/sidebarquickfindoptionsdialog.ui
+++ b/sw/uiconfig/swriter/ui/sidebarquickfindoptionsdialog.ui
@@ -64,6 +64,86 @@
             <property name="can-focus">False</property>
             <property name="hexpand">True</property>
             <property name="row-spacing">6</property>
+            <child>
+              <object class="GtkCheckButton" id="matchcase">
+                <property name="label" translatable="yes" 
context="sidebarquickfindoptionsdialog|matchcase">Match case</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="no-show-all">True</property>
+                <property name="use-underline">True</property>
+                <property name="draw-indicator">True</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="matchcase-atkobject">
+                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="sidebarquickfindoptionsdialog|extended_tip|matchcase">Finds only exact 
case matches.</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="wholewordsonly">
+                <property name="label" translatable="yes" 
context="sidebarquickfindoptionsdialog|wholewordsonly">Whole words 
only</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="no-show-all">True</property>
+                <property name="use-underline">True</property>
+                <property name="draw-indicator">True</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="wholewordsonly-atkobject">
+                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="sidebarquickfindoptionsdialog|extended_tip|wholewordsonly">Finds only 
whole words.</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="comments">
+                <property name="label" translatable="yes" 
context="sidebarquickfindoptionsdialog|comments">Comments</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="no-show-all">True</property>
+                <property name="use-underline">True</property>
+                <property name="draw-indicator">True</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="comments-atkobject">
+                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="sidebarquickfindoptionsdialog|extended_tip|comments">Allow search in 
comments.</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="regularexpressions">
+                <property name="label" translatable="yes" 
context="sidebarquickfindoptionsdialog|regularexpressions">Regular 
expressions</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="no-show-all">True</property>
+                <property name="use-underline">True</property>
+                <property name="draw-indicator">True</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="regularexpressions-atkobject">
+                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="sidebarquickfindoptionsdialog|extended_tip|regularexpressions">Search 
using regular expression.</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">3</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkBox" id="box3">
                 <property name="visible">True</property>
@@ -115,47 +195,7 @@
               </object>
               <packing>
                 <property name="left-attach">0</property>
-                <property name="top-attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="matchcase">
-                <property name="label" translatable="yes" 
context="sidebarquickfindoptionsdialog|matchcase">Match case</property>
-                <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">False</property>
-                <property name="no-show-all">True</property>
-                <property name="use-underline">True</property>
-                <property name="draw-indicator">True</property>
-                <child internal-child="accessible">
-                  <object class="AtkObject" id="matchcase-atkobject">
-                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="sidebarquickfindoptionsdialog|extended_tip|matchcase">Finds only exact 
case matches.</property>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="wholewordsonly">
-                <property name="label" translatable="yes" 
context="sidebarquickfindoptionsdialog|wholewordsonly">Whole words 
only</property>
-                <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">False</property>
-                <property name="no-show-all">True</property>
-                <property name="use-underline">True</property>
-                <property name="draw-indicator">True</property>
-                <child internal-child="accessible">
-                  <object class="AtkObject" id="wholewordsonly-atkobject">
-                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="sidebarquickfindoptionsdialog|extended_tip|wholewordsonly">Finds only 
whole words.</property>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">1</property>
+                <property name="top-attach">4</property>
               </packing>
             </child>
           </object>

Reply via email to