desktop/qa/desktop_lib/test_desktop_lib.cxx | 70 ++++++++++++++++++++++++++++ svx/source/dialog/srchdlg.cxx | 30 +++++++----- 2 files changed, 88 insertions(+), 12 deletions(-)
New commits: commit aa7475bf1ce5a4e0f168328c685b75476aeb9c14 Author: Gökay Şatır <[email protected]> AuthorDate: Wed Sep 17 15:57:49 2025 +0300 Commit: Gökay ŞATIR <[email protected]> CommitDate: Wed Sep 24 13:51:14 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]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191404 Tested-by: Jenkins Reviewed-by: Gökay ŞATIR <[email protected]> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 68dc0b6cbfa6..aa39be86eddb 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -150,6 +150,7 @@ public: void testGetPartPageRectangles(); void testSearchCalc(); void testPropertySettingOnFormulaBar(); + void testSearchTermReset(); void testFormulaBarAcceptButton(); void testSearchAllNotificationsCalc(); void testPaintTile(); @@ -229,6 +230,7 @@ public: CPPUNIT_TEST(testGetPartPageRectangles); CPPUNIT_TEST(testSearchCalc); CPPUNIT_TEST(testPropertySettingOnFormulaBar); + CPPUNIT_TEST(testSearchTermReset); CPPUNIT_TEST(testFormulaBarAcceptButton); CPPUNIT_TEST(testSearchAllNotificationsCalc); CPPUNIT_TEST(testPaintTile); @@ -2268,6 +2270,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), @@ -2345,11 +2349,42 @@ public: ++m_nColorPaletteCallbackCount; } break; + case LOK_CALLBACK_WINDOW: + { + m_JSONDialog.clear(); + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, m_JSONDialog); + + if (m_JSONDialog.find("title") != m_JSONDialog.not_found() && m_JSONDialog.get_child("title").get_value<std::string>() == "Find and Replace") + { + m_findReplaceDialogId = std::atoi(m_JSONDialog.get_child("id").get_value<std::string>().c_str()); + // Set search term to something random and make sure it is read from incoming JSON (LOK_CALLBACK_JSDIALOG). + m_searchTerm = "something random"; + } + } + break; case LOK_CALLBACK_JSDIALOG: { m_JSONDialog.clear(); std::stringstream aStream(pPayload); boost::property_tree::read_json(aStream, m_JSONDialog); + + 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: @@ -3179,6 +3214,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 45f908ce5e5c..6841fe36a0f5 100644 --- a/svx/source/dialog/srchdlg.cxx +++ b/svx/source/dialog/srchdlg.cxx @@ -309,6 +309,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_aPresentIdle.SetTimeout(50); @@ -969,24 +971,28 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern ) bool bSetSearch = !(m_nModifyFlag & ModifyFlags::Search); bool bSetReplace = !(m_nModifyFlag & ModifyFlags::Replace); - if (!(m_pSearchItem->GetSearchString().isEmpty()) && bSetSearch) - m_xSearchLB->set_entry_text(m_pSearchItem->GetSearchString()); - else if (!m_aSearchStrings.empty()) + if (!comphelper::LibreOfficeKit::isActive()) { - bool bAttributes = ((m_pSearchList && m_pSearchList->Count()) - || (m_pReplaceList && m_pReplaceList->Count())); + if (!(m_pSearchItem->GetSearchString().isEmpty()) && bSetSearch) + m_xSearchLB->set_entry_text(m_pSearchItem->GetSearchString()); + else if (!m_aSearchStrings.empty()) + { + bool bAttributes = ((m_pSearchList && m_pSearchList->Count()) + || (m_pReplaceList && m_pReplaceList->Count())); - if ( bSetSearch && !bAttributes ) - m_xSearchLB->set_entry_text(m_aSearchStrings[0]); + if ( bSetSearch && !bAttributes ) + m_xSearchLB->set_entry_text(m_aSearchStrings[0]); - OUString aReplaceTxt = m_pSearchItem->GetReplaceString(); + OUString aReplaceTxt = m_pSearchItem->GetReplaceString(); - if (!m_aReplaceStrings.empty()) - aReplaceTxt = m_aReplaceStrings[0]; + if (!m_aReplaceStrings.empty()) + aReplaceTxt = m_aReplaceStrings[0]; - if ( bSetReplace && !bAttributes ) - m_xReplaceLB->set_entry_text( aReplaceTxt ); + if ( bSetReplace && !bAttributes ) + m_xReplaceLB->set_entry_text( aReplaceTxt ); + } } + m_xSearchLB->show(); if (m_bConstruct)
