summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-03-19 15:28:32 -0400
committerAron Budea <aron.budea@collabora.com>2024-03-28 22:46:56 +1030
commit7a7df4c0ea28e460ac6781d54f7da95a19355dde (patch)
tree2866a58a0a56fb79b0235aeb8342b05f3ba99aa9
parentd8ff9e1e259f7b11940f76d1055bce3dd44f0844 (diff)
related tdf#147583 sw find: fix backwards search for string at end of para
Prior to this fix, it was finding every single character in the document when searching for ".$". Interestingly, the unit test worked even before the patch. Not sure how that could be possible... make CppunitTest_sw_uiwriter7 \ CPPUNIT_TEST_NAME=testTdf147583_backwardSearch Change-Id: I20779898c01736eb39ecd7db7d66c2c24e4358b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165037 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit e830394c068c229bb840018f2f0e8810da6a1487) (cherry picked from commit 5a78a44c486a2a49532d32a8ef53b2f2b4833ffe)
-rw-r--r--sw/qa/extras/uiwriter/uiwriter4.cxx5
-rw-r--r--sw/source/core/crsr/findtxt.cxx19
2 files changed, 24 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx
index e9e6eb2bd148..7c2a2f930a09 100644
--- a/sw/qa/extras/uiwriter/uiwriter4.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter4.cxx
@@ -4193,6 +4193,11 @@ void SwUiWriterTest4::testTdf147583_backwardSearch()
xIndex.set(xSearch->findAll(xSearchDes), uno::UNO_SET_THROW);
// should actually be 10 (including the empty para with the comment marker, and the last para)
CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xIndex->getCount());
+
+ xSearchDes->setSearchString(".$"); // any last character (not just full-stops) in a paragraph
+ xIndex.set(xSearch->findAll(xSearchDes), uno::UNO_SET_THROW);
+ // should be one for every non-empty paragraph
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(14), xIndex->getCount());
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest4);
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index 1f2d130f7147..06f72ea06306 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -734,6 +734,25 @@ bool DoSearch(SwPaM & rSearchPam,
SwTextNode const*const pNode, SwTextFrame const*const pFrame,
SwRootFrame const*const pLayout, SwPaM* pPam)
{
+ if (bRegSearch && rSearchOpt.searchString.endsWith("$"))
+ {
+ bool bAlwaysSearchingForEndOfPara = true;
+ sal_Int32 nIndex = 0;
+ while ((nIndex = rSearchOpt.searchString.indexOf("|", nIndex)) != -1)
+ {
+ if (!nIndex || rSearchOpt.searchString[nIndex - 1] != '$')
+ {
+ bAlwaysSearchingForEndOfPara = false;
+ break;
+ }
+ ++nIndex;
+ }
+ // when searching for something at the end of the paragraph, the para end must be in range
+ const AmbiguousIndex& rParaEnd = bSrchForward ? nEnd : nStart;
+ if (bAlwaysSearchingForEndOfPara && nTextLen.GetAnyIndex() != rParaEnd.GetAnyIndex())
+ return false;
+ }
+
bool bFound = false;
OUString sCleanStr;
std::vector<AmbiguousIndex> aFltArr;