sc/qa/extras/macros-test.cxx            |   26 ++++++++++++++++++++++++++
 sc/qa/extras/testdocuments/tdf89920.ods |binary
 sc/source/core/data/table6.cxx          |   15 ++++-----------
 3 files changed, 30 insertions(+), 11 deletions(-)

New commits:
commit 56ae7d01505fdae421109cfc78449230ba589d79
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Mon Mar 13 08:49:27 2023 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Mon Apr 3 08:43:06 2023 +0200

    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.heini...@yahoo.de>

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
Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf89920.ods 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);

Reply via email to