tdf#138739 sw: fix regression of first paragraph

First paragraph of the document lost its formatting
from commit 056933bc55608d0ca061539ae124d7b9386cdb62.
(tdf#137802 sw: fix crash on deleting last paragraph).

This reverts commit 056933bc55608d0ca061539ae124d7b9386cdb62.

Note: last take went wrong so this is a follow up for
commit 25ca25ee25278536c56a2ac4a63af91100ce4d2e
(tdf#138739 sw: fix regression of first paragraph).
Hopefuly it will be fine.

Change-Id: Id8a19c47f172b25cd5559f5823f19b3faf38cfd2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108196
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 7957123a144bfe66a99aa0d30a47900b6b621a70)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109010
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf138739.docx b/sw/qa/extras/ooxmlexport/data/tdf138739.docx
new file mode 100755
index 0000000..7b5bb30
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf138739.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 7dd4fea..c875d56 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -240,6 +240,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf136404, "tdf136404.fodt")
    CPPUNIT_ASSERT_EQUAL(OUString("8"), xEnumerationAccess7->getPresentation(false).trim());
}

DECLARE_OOXMLEXPORT_TEST(testTdf138739, "tdf138739.docx")
{
    uno::Reference<beans::XPropertySet> xParaProps(getParagraph(1), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Font type name does not match!", OUString("Comic Sans MS"),
                                 xParaProps->getPropertyValue("CharFontName").get<OUString>());
}

DECLARE_OOXMLEXPORT_TEST(testTdf123390, "tdf123390.fodt")
{
    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 5457b8b..4d44d1c 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -92,12 +92,7 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, bool bCopyText)
    }
    catch (uno::Exception&)
    {
        // Before the textframe was appended now it is inserted to the begin of the doc in order
        // to prevent crash when someone removes the para where the textframe anchored:
        uno::Reference<text::XTextCursor> xCursor = xTextDocument->getText()->createTextCursor();
        xCursor->gotoStart(false);
        xTextContentAppend->insertTextContentWithProperties(
            xTextFrame, uno::Sequence<beans::PropertyValue>(), xCursor->getStart());
        xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>());
    }
    // Link FLY and DRAW formats, so it becomes a text box (needed for syncProperty calls).
    uno::Reference<text::XTextFrame> xRealTextFrame(xTextFrame, uno::UNO_QUERY);