Rebased ref, commits from common ancestor:
commit 5fd6db8a80f1292cf428a1a49d7da5c058a26722
Author:     Gökay Şatır <[email protected]>
AuthorDate: Wed Sep 17 15:57:49 2025 +0300
Commit:     Andras Timar <[email protected]>
CommitDate: Thu Sep 18 09:24:10 2025 +0200

    cool#12896: Reset search string when Online is active.
    
    Issue: Core side remembers the last searched text but Online side may have 
multiple users at the same time.
    Other users see the current user's last searched text when they use search 
dialog.
    This commit resets the searched text every time to avoid the issue.
    
    Signed-off-by: Gökay Şatır <[email protected]>
    Change-Id: Iecf1cca6a2c9ce4b278cc6ebe68bb71dd9be9f4e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191089
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index b466e07532b6..df6976bbf21a 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -156,6 +156,7 @@ public:
     void testGetPartPageRectangles();
     void testSearchCalc();
     void testPropertySettingOnFormulaBar();
+    void testSearchTermReset();
     void testFormulaBarAcceptButton();
     void testSearchAllNotificationsCalc();
     void testPaintTile();
@@ -235,6 +236,7 @@ public:
     CPPUNIT_TEST(testGetPartPageRectangles);
     CPPUNIT_TEST(testSearchCalc);
     CPPUNIT_TEST(testPropertySettingOnFormulaBar);
+    CPPUNIT_TEST(testSearchTermReset);
     CPPUNIT_TEST(testFormulaBarAcceptButton);
     CPPUNIT_TEST(testSearchAllNotificationsCalc);
     CPPUNIT_TEST(testPaintTile);
@@ -2274,6 +2276,8 @@ public:
     boost::property_tree::ptree m_aCommentCallbackResult;
     boost::property_tree::ptree m_aColorPaletteCallbackResult;
     RedlineInfo m_aLastRedlineInfo;
+    std::string m_searchTerm;
+    int m_findReplaceDialogId;
 
     ViewCallback(LibLODocument_Impl* pDocument)
         : mpDocument(pDocument),
@@ -2356,6 +2360,27 @@ public:
             m_JSONDialog.clear();
             std::stringstream aStream(pPayload);
             boost::property_tree::read_json(aStream, m_JSONDialog);
+
+            if (m_JSONDialog.find("id") != m_JSONDialog.not_found() && 
m_JSONDialog.get_child("id").get_value<std::string>() == "FindReplaceDialog")
+            {
+                m_findReplaceDialogId = 
m_JSONDialog.get_child("lokWindowId").get_value<int>();
+            }
+            if (m_JSONDialog.find("jsontype") != m_JSONDialog.not_found() && 
m_JSONDialog.get_child("jsontype").get_value<std::string>() == "dialog")
+            {
+                if (m_JSONDialog.find("data") != m_JSONDialog.not_found())
+                {
+                    if (m_JSONDialog.get_child("data").find("control_id") != 
m_JSONDialog.get_child("data").not_found())
+                    {
+                        if 
(m_JSONDialog.get_child("data").get_child("control_id").get_value<std::string>()
 == "searchterm")
+                        {
+                            if (m_JSONDialog.get_child("data").find("text") != 
m_JSONDialog.get_child("data").not_found())
+                            {
+                                m_searchTerm = 
m_JSONDialog.get_child("data").get_child("text").get_value<std::string>();
+                            }
+                        }
+                    }
+                }
+            }
         }
         break;
         case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
@@ -3187,6 +3212,41 @@ void DesktopLOKTest::testPropertySettingOnFormulaBar()
     CPPUNIT_ASSERT_EQUAL(false, aView.m_stateBold); // This line doesn't pass 
without the fix in this commit.
 }
 
+void DesktopLOKTest::testSearchTermReset()
+{
+    LibLibreOffice_Impl aOffice;
+    LibLODocument_Impl* pDocument = loadDoc("empty.ods");
+    Scheduler::ProcessEventsToIdle();
+
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    Scheduler::ProcessEventsToIdle();
+
+    ViewCallback aView(pDocument);
+    Scheduler::ProcessEventsToIdle();
+
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:SearchDialog", nullptr, 
false);
+    Scheduler::ProcessEventsToIdle();
+
+    // Send "something" as current search string (searchterm).
+    pDocument->pClass->sendDialogEvent(pDocument, aView.m_findReplaceDialogId, 
"{\"id\":\"searchterm\", \"cmd\": \"change\", \"data\": \"something\", 
\"type\": \"combobox\"}");
+    Scheduler::ProcessEventsToIdle();
+
+    // Press search button.
+    pDocument->pClass->sendDialogEvent(pDocument, aView.m_findReplaceDialogId, 
"{\"id\":\"search\", \"cmd\": \"click\", \"data\": \"undefined\", \"type\": 
\"pushbutton\"}");
+    Scheduler::ProcessEventsToIdle();
+
+    // Close the dialog.
+    pDocument->pClass->sendDialogEvent(pDocument, aView.m_findReplaceDialogId, 
"{\"id\":\"__DIALOG__\", \"cmd\": \"close\", \"data\": \"null\", \"type\": 
\"dialog\"}");
+    Scheduler::ProcessEventsToIdle();
+
+    // Reopen search dialog.
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:SearchDialog", nullptr, 
false);
+    Scheduler::ProcessEventsToIdle();
+
+    // We should have got the "searchterm" again. It should be empty. Below 
line doesn't pass without the changes in this commit.
+    CPPUNIT_ASSERT_EQUAL(std::string(""), aView.m_searchTerm);
+}
+
 void DesktopLOKTest::testFormulaBarAcceptButton()
 {
     LibLibreOffice_Impl aOffice;
diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx
index e4bfe3b2bcaa..9cc7fda366e1 100644
--- a/svx/source/dialog/srchdlg.cxx
+++ b/svx/source/dialog/srchdlg.cxx
@@ -311,6 +311,8 @@ SvxSearchDialog::SvxSearchDialog(weld::Window* pParent, 
SfxChildWindow* pChildWi
     {
         m_xCloseBtn->hide();
         m_xHelpBtn->hide();
+        m_xSearchLB->set_entry_text(u""_ustr);
+        m_xReplaceLB->set_entry_text(u""_ustr);
         m_xSearchLB->grab_focus();
     }
 
@@ -990,25 +992,29 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
         bool bSetSearch = !( nModifyFlag & ModifyFlags::Search );
         bool bSetReplace = !( nModifyFlag & ModifyFlags::Replace );
 
-        if ( !(pSearchItem->GetSearchString().isEmpty()) && bSetSearch )
-            m_xSearchLB->set_entry_text( pSearchItem->GetSearchString() );
-        else if (!aSearchStrings.empty())
+        if (!comphelper::LibreOfficeKit::isActive())
         {
-            bool bAttributes =
-                ( ( pSearchList && pSearchList->Count() ) ||
-                  ( pReplaceList && pReplaceList->Count() ) );
+            if ( !(pSearchItem->GetSearchString().isEmpty()) && bSetSearch )
+                m_xSearchLB->set_entry_text( pSearchItem->GetSearchString() );
+            else if (!aSearchStrings.empty())
+            {
+                bool bAttributes =
+                    ( ( pSearchList && pSearchList->Count() ) ||
+                    ( pReplaceList && pReplaceList->Count() ) );
 
-            if ( bSetSearch && !bAttributes )
-                m_xSearchLB->set_entry_text(aSearchStrings[0]);
+                if ( bSetSearch && !bAttributes )
+                    m_xSearchLB->set_entry_text(aSearchStrings[0]);
 
-            OUString aReplaceTxt = pSearchItem->GetReplaceString();
+                OUString aReplaceTxt = pSearchItem->GetReplaceString();
 
-            if (!aReplaceStrings.empty())
-                aReplaceTxt = aReplaceStrings[0];
+                if (!aReplaceStrings.empty())
+                    aReplaceTxt = aReplaceStrings[0];
 
-            if ( bSetReplace && !bAttributes )
-                m_xReplaceLB->set_entry_text( aReplaceTxt );
+                if ( bSetReplace && !bAttributes )
+                    m_xReplaceLB->set_entry_text( aReplaceTxt );
+            }
         }
+
         m_xSearchLB->show();
 
         if ( bConstruct )
commit 58e8f5841d4d6bd71d4bc9d417eb761ece612014
Author:     NickWingate <[email protected]>
AuthorDate: Wed Aug 27 13:49:00 2025 +0100
Commit:     Andras Timar <[email protected]>
CommitDate: Thu Sep 18 09:24:06 2025 +0200

    Find Dialog: focus search entry on open
    
    Signed-off-by: NickWingate <[email protected]>
    Change-Id: I44b8d36661d6fd290abc9f6b86831188a2aac88d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190288
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Szymon Kłos <[email protected]>

diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx
index 9b2eff684252..e4bfe3b2bcaa 100644
--- a/svx/source/dialog/srchdlg.cxx
+++ b/svx/source/dialog/srchdlg.cxx
@@ -311,6 +311,7 @@ SvxSearchDialog::SvxSearchDialog(weld::Window* pParent, 
SfxChildWindow* pChildWi
     {
         m_xCloseBtn->hide();
         m_xHelpBtn->hide();
+        m_xSearchLB->grab_focus();
     }
 
     m_aPresentIdle.SetTimeout(50);

Reply via email to