sw/qa/extras/ooxmlexport/data/tdf164474.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx   |   24 ++++++++++++++++++++++++
 sw/source/core/unocore/unotext.cxx           |    5 ++++-
 3 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 8a8b3ab11db23519fbe5ea6b4939628f56cee953
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Dec 27 17:32:06 2024 +0500
Commit:     Aron Budea <[email protected]>
CommitDate: Tue Sep 30 11:32:36 2025 +0200

    tdf#164474: do not delete anchor node, when the anchor didn't move
    
    Regression since commit f09420fa189be5165b0311083ba127073500a121
    (tdf#158855: Make sure to not add extra paragraph after a table in
    a section, 2023-12-25).
    The code in SwXText::convertToTextFrame still relied on existing
    extra paragraph after the table, which now gets removed.
    
    Change-Id: I562058c15e323a23e3278fd7743f877eeec25999
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179443
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 647aa0f596e899176a088e47c16124cccdff4fc8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191646
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Aron Budea <[email protected]>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf164474.docx 
b/sw/qa/extras/ooxmlexport/data/tdf164474.docx
new file mode 100644
index 000000000000..566a383583f5
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf164474.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 9b9796098788..b7a31a6833bf 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -1269,6 +1269,30 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf165059_moveFromTo)
     assertXPath(p_XmlDoc, "//w:delText"_ostr, 1);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf164474)
+{
+    // Given a document with a table inside a frame anchored to an empty 
section
+    createSwDoc("tdf164474.docx");
+
+    // The table must not get lost on import
+    {
+        auto 
xTextTablesSupplier(mxComponent.queryThrow<text::XTextTablesSupplier>());
+        auto 
xTables(xTextTablesSupplier->getTextTables().queryThrow<container::XIndexAccess>());
+        // Without the fix, this would fail with
+        // - Expected: 1
+        // - Actual  : 0
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+    }
+
+    // Test also after save-and-reload:
+    saveAndReload(u"Office Open XML Text"_ustr);
+    {
+        auto 
xTextTablesSupplier(mxComponent.queryThrow<text::XTextTablesSupplier>());
+        auto 
xTables(xTextTablesSupplier->getTextTables().queryThrow<container::XIndexAccess>());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+    }
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/unocore/unotext.cxx 
b/sw/source/core/unocore/unotext.cxx
index 3af3fc6113bb..72f6cfe65172 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1683,6 +1683,7 @@ SwXText::convertToTextFrame(
         assert(pTextNode);
         if (!pTextNode || !pTextNode->Len()) // don't remove if it contains 
text!
         {
+            bool bDel = false;
             {   // has to be in a block to remove the SwContentIndexes before
                 // DelFullPara is called
                 SwPaM aMovePam( pStartPam->GetPointNode() );
@@ -1730,9 +1731,11 @@ SwXText::convertToTextFrame(
                             }
                         }
                     }
+                    bDel = true; // Only delete the ex-anchor, if the frame is 
moved successfully
                 }
             }
-            m_pDoc->getIDocumentContentOperations().DelFullPara(*pStartPam);
+            if (bDel)
+                
m_pDoc->getIDocumentContentOperations().DelFullPara(*pStartPam);
         }
     }
     catch (const lang::IllegalArgumentException& rIllegal)

Reply via email to