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 647aa0f596e899176a088e47c16124cccdff4fc8 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Dec 27 17:32:06 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Dec 27 14:56:12 2024 +0100 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 <mike.kagan...@collabora.com> Tested-by: Jenkins 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 0447f0b78f12..472a4f3cc179 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -1204,6 +1204,30 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf164065) CPPUNIT_ASSERT_EQUAL(u"a"_ustr, xCell->getString()); } +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 c4a72376d5c3..684ea45de5a0 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -1682,6 +1682,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() ); @@ -1729,9 +1730,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)