summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-07-15 16:44:37 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-07-17 17:48:25 +0200
commitca2dfac3e790fb384e904502fe1ededd695001af (patch)
tree9ec89aeee2da63a9c5c277837946af2206f65ced /sw
parentba4bc66301e0cb30379f19b9c19e320a533daa42 (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>
Diffstat (limited to 'sw')
-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 54faad3d233c..38a700463846 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -10,6 +10,7 @@
#include <swmodeltestbase.hxx>
#include <com/sun/star/text/XTextAppend.hpp>
+#include <com/sun/star/text/XTextFrame.hpp>
#include <wrtsh.hxx>
#include <unotextrange.hxx>
@@ -58,6 +59,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 dcb6d0ede363..c277d1179789 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;