summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2023-03-13 08:49:27 +0100
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2023-04-03 08:43:06 +0200
commit56ae7d01505fdae421109cfc78449230ba589d79 (patch)
treed4bde0406a42efeb74e55580e425b1cd2813d1da
parentd36145d7cf6ca4d6072d4ab0a709bb8fe866336c (diff)
tdf#89920 - Handle embedded newline in Calc's search cell
If the replaced string contains a newline after find and replace, insert an edit cell in order to handle an embedded line correctly regardless of the content in the source cell. Change-Id: Ic8a5fc80b85546897572a228511b319cd5a8b9aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148752 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
-rw-r--r--sc/qa/extras/macros-test.cxx26
-rw-r--r--sc/qa/extras/testdocuments/tdf89920.odsbin0 -> 11183 bytes
-rw-r--r--sc/source/core/data/table6.cxx15
3 files changed, 30 insertions, 11 deletions
diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index a77147504ae4..ec41a2fbe4a9 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -279,6 +279,32 @@ CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf142033)
CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + u"newlines"), rDoc.GetString(ScAddress(1,1,0)));
}
+CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf89920)
+{
+ loadFromURL(u"tdf89920.ods");
+
+ executeMacro("vnd.sun.Star.script:Standard.Module1.SearchAndReplaceNewline?language=Basic&"
+ "location=document");
+
+ // Export to ODS
+ saveAndReload("calc8");
+
+ xmlDocUniquePtr pContentXml = parseExport("content.xml");
+ CPPUNIT_ASSERT(pContentXml);
+
+ assertXPathContent(pContentXml,
+ "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
+ "table:table-row[1]/table:table-cell[1]/text:p[1]",
+ "aa bb");
+
+ // Without the fix in place, this test would have failed here with
+ // - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0
+ assertXPathContent(pContentXml,
+ "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
+ "table:table-row[1]/table:table-cell[1]/text:p[2]",
+ "cc dd");
+}
+
CPPUNIT_TEST_FIXTURE(ScMacrosTest, testPasswordProtectedUnicodeString)
{
const OUString sCorrectString(u"English Русский 中文");
diff --git a/sc/qa/extras/testdocuments/tdf89920.ods b/sc/qa/extras/testdocuments/tdf89920.ods
new file mode 100644
index 000000000000..216a5cc75d9d
--- /dev/null
+++ b/sc/qa/extras/testdocuments/tdf89920.ods
Binary files differ
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index 1f0fc1efbf3d..1ea4a5ace99d 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -35,14 +35,11 @@
namespace {
-bool lcl_GetTextWithBreaks( const EditTextObject& rData, ScDocument* pDoc, OUString& rVal )
+void lcl_GetTextWithBreaks( const EditTextObject& rData, ScDocument* pDoc, OUString& rVal )
{
- // true = more than 1 paragraph
-
EditEngine& rEngine = pDoc->GetEditEngine();
rEngine.SetText(rData);
rVal = rEngine.GetText();
- return ( rEngine.GetParagraphCount() > 1 );
}
}
@@ -81,7 +78,6 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum
pNote = nullptr;
}
- bool bMultiLine = false;
CellType eCellType = aCell.getType();
switch (rSearchItem.GetCellType())
{
@@ -90,7 +86,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum
if ( eCellType == CELLTYPE_FORMULA )
aString = aCell.getFormula()->GetFormula(rDocument.GetGrammar());
else if ( eCellType == CELLTYPE_EDIT )
- bMultiLine = lcl_GetTextWithBreaks(*aCell.getEditText(), &rDocument, aString);
+ lcl_GetTextWithBreaks(*aCell.getEditText(), &rDocument, aString);
else
{
if( !bSearchFormatted )
@@ -102,7 +98,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum
}
case SvxSearchCellType::VALUE:
if ( eCellType == CELLTYPE_EDIT )
- bMultiLine = lcl_GetTextWithBreaks(*aCell.getEditText(), &rDocument, aString);
+ lcl_GetTextWithBreaks(*aCell.getEditText(), &rDocument, aString);
else
{
if( !bSearchFormatted )
@@ -114,10 +110,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum
case SvxSearchCellType::NOTE:
{
if (pNote)
- {
aString = pNote->GetText();
- bMultiLine = pNote->HasMultiLineText();
- }
break;
}
default:
@@ -264,7 +257,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum
pFCell->SetMatColsRows( nMatCols, nMatRows );
aCol[nCol].SetFormulaCell(nRow, pFCell);
}
- else if ( bMultiLine && aString.indexOf('\n') != -1 )
+ else if (aString.indexOf('\n') != -1 && eCellType != CELLTYPE_FORMULA)
{
ScFieldEditEngine& rEngine = rDocument.GetEditEngine();
rEngine.SetTextCurrentDefaults(aString);