summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Bakos (NISZ) <bakos.attilakaroly@nisz.hu>2020-10-15 16:45:15 +0200
committerGabor Kelemen <kelemen.gabor2@nisz.hu>2021-04-21 14:11:37 +0200
commitf9a26bd2f5fae14ed99d8240a090b9a5aae1fcc2 (patch)
treebfb330e2b0890008800b7c69442acefda3d8f304
parent26b492e47bb0688b3c996698a7e1bd0c544c24c1 (diff)
tdf#137802 sw: fix crash on deleting last paragraph
if the last paragraph of document had a text box anchored to. Change-Id: Ibe29a0f37d06223c31f3add0c194e4414f65d5ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104379 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 056933bc55608d0ca061539ae124d7b9386cdb62) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114354 Tested-by: Gabor Kelemen <kelemen.gabor2@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gabor2@nisz.hu>
-rwxr-xr-xsw/qa/extras/uiwriter/data3/txbx_crash.odtbin0 -> 9369 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter3.cxx31
-rw-r--r--sw/source/core/doc/textboxhelper.cxx7
3 files changed, 37 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data3/txbx_crash.odt b/sw/qa/extras/uiwriter/data3/txbx_crash.odt
new file mode 100755
index 000000000000..0a029da88289
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data3/txbx_crash.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 245c57ebb788..60e2d5067166 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -772,6 +772,37 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf107893)
CPPUNIT_ASSERT_MESSAGE("Textbox cannot be readd after Undo!", pTxBxFrm);
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, TestTextBoxCrashAfterLineDel)
+{
+ // Open the desired file
+ load(DATA_DIRECTORY, "txbx_crash.odt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+
+ // Get the Writer shell
+ SwWrtShell* pWrtSh = pTextDoc->GetDocShell()->GetWrtShell();
+ CPPUNIT_ASSERT(pWrtSh);
+
+ // Get the format of the shape
+ const SwFrameFormats& rFrmFormats = *pWrtSh->GetDoc()->GetSpzFrameFormats();
+ CPPUNIT_ASSERT(rFrmFormats.size() >= size_t(o3tl::make_unsigned(1)));
+ SwFrameFormat* pShape = rFrmFormats.front();
+ CPPUNIT_ASSERT(pShape);
+
+ // Add a textbox
+ SwTextBoxHelper::create(pShape);
+ SwFrameFormat* pTxBxFrm = SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
+ CPPUNIT_ASSERT(pTxBxFrm);
+
+ // remove the last paragraph
+ auto xCursor = getParagraph(1)->getText()->createTextCursor();
+ xCursor->gotoEnd(false);
+ xCursor->goLeft(3, true);
+
+ // This caused crash before, now it should pass with the patch.
+ xCursor->setString(OUString());
+}
+
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf96067)
{
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 98debf9b59d4..43e77acd9fea 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -89,7 +89,12 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, bool bCopyText)
}
catch (uno::Exception&)
{
- xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>());
+ // 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());
}
// Link FLY and DRAW formats, so it becomes a text box (needed for syncProperty calls).
uno::Reference<text::XTextFrame> xRealTextFrame(xTextFrame, uno::UNO_QUERY);