sw/qa/extras/ooxmlimport/data/tdf168567.docx |binary sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 39 +++++++++++++++++++++++++++ writerfilter/source/dmapper/DomainMapper.cxx | 3 ++ 3 files changed, 42 insertions(+)
New commits: commit ae233fb30eb3a4287f7f9210c86af47f3c3fc16e Author: Karthik Godha <[email protected]> AuthorDate: Thu Oct 16 11:52:06 2025 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Fri Oct 24 17:41:40 2025 +0200 tdf#168567: Fix import of SDTs with empty content regression from commit 7c4dba1deffd81f647a4a3be7a79f68f3bf9f1 SDTs(content controls) with empty paragraph content are not properly imported. Change-Id: I340a060f03b419b3352fad2a8fb5ac3af043be54 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192466 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> (cherry picked from commit 72a326b2899115860a87cfa55b82f745a76128da) diff --git a/sw/qa/extras/ooxmlimport/data/tdf168567.docx b/sw/qa/extras/ooxmlimport/data/tdf168567.docx new file mode 100644 index 000000000000..43803f847408 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf168567.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index 642c05b14aa8..7d55d01d964a 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -22,6 +22,7 @@ #include <com/sun/star/style/BreakType.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/table/XCellRange.hpp> #include <comphelper/propertysequence.hxx> #include <vcl/BitmapReadAccess.hxx> @@ -1285,6 +1286,44 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154370) CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, ePropertyState); } } + +CPPUNIT_TEST_FIXTURE(Test, testTdf168567) +{ + createSwDoc("tdf168567.docx"); + + // Access the first table in the doc + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XTableRows> xRows = xTable->getRows(); + uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY); + + sal_Int32 nLastRow = xRows->getCount() - 1; + + // Check if all cells in the last row contain `Content Controls`(SDTs) + for (sal_Int32 col = 0; col < xTable->getColumns()->getCount(); col++) + { + uno::Reference<text::XText> xCell(xCellRange->getCellByPosition(col, nLastRow), + uno::UNO_QUERY); + + uno::Reference<container::XEnumerationAccess> xParaAccess(xCell, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParaAccess->createEnumeration(); + + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + + // Check if it's a content control + // Without the fix the last cell will result false + OUString aPortionType; + xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); + } +} + // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 2ec441c22153..822e29398588 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -4279,6 +4279,9 @@ void DomainMapper::lcl_utext(const sal_Unicode *const data_, size_t len) { if (bNewLine) { + if (!m_pImpl->m_pSdtHelper->isFieldStartRangeSet()) + m_pImpl->m_pSdtHelper->setFieldStartRange(GetCurrentTextRange()->getEnd()); + m_pImpl->m_pSdtHelper->createPlainTextControl(); finishParagraph(); return;
