summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-07-15 16:44:37 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-07-18 14:30:31 +0200
commit06f57231af98ec7093de705d5a310c86c7783d99 (patch)
tree5c4074d596ca04072248ac5ca0d8b7dd80db3f18
parent0b2f21056ccd8a3698593fdf6e2e31fd3743590f (diff)
sw: fix crash when using anchor of at-paragraph fly ...
... to insert fieldmark; the problem is that the anchor doesn't have SwIndex so the resulting sw::mark::Fieldmark's positions won't have SwIndex either, so they aren't updated when its dummy chars are inserted in lcl_SetFieldMarks(). Change-Id: Id6281f45aa1f1337f1ae599877f155b129389d81 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98852 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de> (cherry picked from commit ca2dfac3e790fb384e904502fe1ededd695001af) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98962 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r--sw/qa/core/unocore/unocore.cxx22
-rw-r--r--sw/source/core/unocore/unodraw.cxx9
-rw-r--r--sw/source/core/unocore/unoframe.cxx9
3 files changed, 38 insertions, 2 deletions
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index d8d72ecf369f..a4a39489da60 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -15,6 +15,7 @@
#include <com/sun/star/text/AutoTextContainer.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/XAutoTextGroup.hpp>
+#include <com/sun/star/text/XTextFrame.hpp>
#include <com/sun/star/text/XTextPortionAppend.hpp>
#include <com/sun/star/text/XTextContentAppend.hpp>
#include <com/sun/star/text/XTextRangeCompare.hpp>
@@ -86,6 +87,27 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081)
CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText());
}
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, flyAtParaAnchor)
+{
+ mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+ uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW);
+ uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW);
+ uno::Reference<text::XTextFrame> const xTextFrame(
+ xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY_THROW);
+ uno::Reference<beans::XPropertySet> const xFrameProps(xTextFrame, uno::UNO_QUERY_THROW);
+ xFrameProps->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH));
+ auto const xText = xTD->getText();
+ auto const xTextCursor = xText->createTextCursor();
+ CPPUNIT_ASSERT(xTextCursor.is());
+ xText->insertTextContent(xTextCursor, xTextFrame, false);
+ auto const xAnchor = xTextFrame->getAnchor();
+ uno::Reference<text::XTextContent> const xFieldmark(
+ xMSF->createInstance("com.sun.star.text.Fieldmark"), uno::UNO_QUERY_THROW);
+ // this crashed because the anchor didn't have SwIndex
+ xText->insertTextContent(xAnchor, xFieldmark, false);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 5e3ec6b23d37..d21756c65720 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -2068,7 +2068,14 @@ uno::Reference< text::XTextRange > SwXShape::getAnchor()
(rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
{
const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
- aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+ if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA)
+ { // ensure that SwXTextRange has SwIndex
+ aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.nNode), nullptr);
+ }
+ else
+ {
+ aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+ }
}
}
else
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index d453f1c79709..f827226d0be4 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2641,7 +2641,14 @@ uno::Reference< text::XTextRange > SwXFrame::getAnchor()
(rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
{
const SwPosition &rPos = *(rAnchor.GetContentAnchor());
- aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+ if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA)
+ { // ensure that SwXTextRange has SwIndex
+ aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.nNode), nullptr);
+ }
+ else
+ {
+ aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+ }
}
return aRef;