sw/qa/extras/ooxmlexport/data/tdf158661_blockSDT.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx         |   62 ++++++++++++++++++
 sw/source/writerfilter/dmapper/SdtHelper.cxx          |    5 -
 3 files changed, 62 insertions(+), 5 deletions(-)

New commits:
commit 62974cf6a8148377091cb709e7e00dacac152093
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Tue Jul 23 20:23:40 2024 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Jul 24 13:50:55 2024 +0200

    tdf#158661 docx import plaintext sdt: remove unnecessary goRight
    
    This fixes a 24.2 regression
    from commit 5082d50d24c3fec4487c724a15eb0d54a82ecd0d
       writerfilter: use content controls for text in block SDTs
    
    which was made even worse
    with 24.2 commit 7c4dba1deffd81f647a4a3be7a79f68f3bf9f1ba.
    
    Initially, the starting mark was made as soon as SdtContent was seen.
    After that, you could get a w:tbl, or a w:tc which could trigger
    the start of a table, and potentially add a dummy paragraph
    which needed to be jumped over (at least for the first SDT,
    but not for subsequent SDTs).
    
    In the second patch, the starting mark was made just before
    the text was appended, so all of the cell/table creation
    has already been completed, so there is no more need to
    jump over any dummy paragraphs, even for the first table.
    
    Affected unit tests were
    - table-start-2-sdt.docx
    - sdt-company-multipara.docx
    - paragraph-sdt.docx
    
    make CppunitTest_sw_ooxmlfieldexport CPPUNIT_TEST_NAME=testParagraphSdt
    make CppunitTest_sw_ooxmlfieldexport \
        CPPUNIT_TEST_NAME=testTdf158661_blockSDT
    
    Change-Id: I4a8359cec27f88f6a2fc0464aa240b523a279e42
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170920
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf158661_blockSDT.docx 
b/sw/qa/extras/ooxmlexport/data/tdf158661_blockSDT.docx
new file mode 100644
index 000000000000..644c67c1e2a0
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf158661_blockSDT.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index a6346350f6b8..ec0037196a3c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -465,6 +465,68 @@ CPPUNIT_TEST_FIXTURE(Test, testParagraphSdt)
     xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
     // The path to w:sdt contained a w:p.
     assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p/w:sdt"_ostr);
+
+    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::XCell> xCell = xTable->getCellByName(u"A1"_ustr);
+    uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphsAccess->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);
+    OUString aPortionType;
+    xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType;
+    CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType);
+    uno::Reference<text::XTextContent> xContentControl;
+    xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl;
+    uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xContentControlEnumAccess(xContentControl, uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xContentControlEnum = 
xContentControlEnumAccess->createEnumeration();
+    uno::Reference<text::XTextRange> 
xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"Android Security Final Design Report"_ustr, 
xTextPortionRange->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf158661_blockSDT)
+{
+    loadAndReload("tdf158661_blockSDT.docx");
+    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::XCell> xCell = xTable->getCellByName(u"A1"_ustr);
+    uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphsAccess->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);
+    OUString aPortionType;
+    xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType;
+    CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType);
+    uno::Reference<text::XTextContent> xContentControl;
+    xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl;
+    uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xContentControlEnumAccess(xContentControl, uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xContentControlEnum = 
xContentControlEnumAccess->createEnumeration();
+    uno::Reference<text::XTextRange> 
xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"Survey Strategy"_ustr, 
xTextPortionRange->getString());
+
+    xTable.set(xTables->getByIndex(1), uno::UNO_QUERY);
+    xCell = xTable->getCellByName(u"A1"_ustr);
+    xParagraphsAccess.set(xCell, uno::UNO_QUERY);
+    xParagraphs = xParagraphsAccess->createEnumeration();
+    xParagraph.set(xParagraphs->nextElement(), uno::UNO_QUERY);
+    xPortions = xParagraph->createEnumeration();
+    xTextPortion.set(xPortions->nextElement(), uno::UNO_QUERY);
+    xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType;
+    CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType);
+    xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl;
+    xContentControlProps.set(xContentControl, uno::UNO_QUERY);
+    xContentControlEnumAccess.set(xContentControl, uno::UNO_QUERY);
+    xContentControlEnum = xContentControlEnumAccess->createEnumeration();
+    xTextPortionRange.set(xContentControlEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"Test"_ustr, xTextPortionRange->getString());
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testSdt2Run)
diff --git a/sw/source/writerfilter/dmapper/SdtHelper.cxx 
b/sw/source/writerfilter/dmapper/SdtHelper.cxx
index 46c818f72015..7687843e7ae3 100644
--- a/sw/source/writerfilter/dmapper/SdtHelper.cxx
+++ b/sw/source/writerfilter/dmapper/SdtHelper.cxx
@@ -360,11 +360,6 @@ void SdtHelper::createPlainTextControl()
 
     try
     {
-        bool bIsInTable = (m_rDM_Impl.hasTableManager() && 
m_rDM_Impl.getTableManager().isInTable())
-                              != (0 < 
m_rDM_Impl.m_StreamStateStack.top().nTableDepth)
-                          && m_rDM_Impl.GetIsDummyParaAddedForTableInSection();
-        if (bIsInTable)
-            xCrsr->goRight(1, false);
         xCrsr->gotoEnd(true);
     }
     catch (uno::Exception&)

Reply via email to