diff options
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 13 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/delete.cxx | 40 |
2 files changed, 53 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 8c07b9d11094..04b2c4df88ba 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -29,6 +29,7 @@ #include <xmloff/odffields.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/dispatch.hxx> +#include <svl/stritem.hxx> #include <txtfrm.hxx> #include <redline.hxx> #include <view.hxx> @@ -1586,6 +1587,18 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageCommentAtChar) getProperty<OUString>(getRun(xPara, 4), "TextPortionType")); CPPUNIT_ASSERT_EQUAL(OUString("Text"), getProperty<OUString>(getRun(xPara, 5), "TextPortionType")); + + // Insert content to the comment, and select the image again. + SfxStringItem aItem(FN_INSERT_STRING, "x"); + pView->GetViewFrame()->GetDispatcher()->ExecuteList(FN_INSERT_STRING, SfxCallMode::SYNCHRON, + { &aItem }); + pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON); + // Now delete the image. + pView->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON); + // Without the accompanying fix in place, this test would have failed with 'Expected: 0; Actual: + // 1', i.e. the comment of the image was not deleted when the image was deleted. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), + pDoc->getIDocumentMarkAccess()->getAnnotationMarksCount()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 4675bcad5149..e783037c9bb9 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -23,6 +23,10 @@ #include <view.hxx> #include <drawbase.hxx> #include <unobaseclass.hxx> +#include <fmtanchr.hxx> +#include <flyfrm.hxx> +#include <ndtxt.hxx> +#include <IDocumentUndoRedo.hxx> #include <i18nutil/unicode.hxx> #include <rtl/character.hxx> @@ -394,8 +398,44 @@ bool SwWrtShell::DelRight() // #108205# Remember object's position. Point aTmpPt = GetObjRect().TopLeft(); + // Remember the anchof of the selected object before deletion. + std::unique_ptr<SwPosition> pAnchor; + SwFlyFrame* pFly = GetSelectedFlyFrame(); + if (pFly) + { + SwFrameFormat* pFormat = pFly->GetFormat(); + if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_CHAR) + { + if (pFormat->GetAnchor().GetContentAnchor()) + { + pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor())); + } + } + } + + // Group deletion of the object and its comment together. + mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr); + DelSelectedObj(); + if (pAnchor) + { + SwTextNode* pTextNode = pAnchor->nNode.GetNode().GetTextNode(); + if (pTextNode) + { + const SwTextField* pField( + pTextNode->GetFieldTextAttrAt(pAnchor->nContent.GetIndex(), true)); + if (pField) + { + // Remove the comment of the deleted object. + *GetCurrentShellCursor().GetPoint() = *pAnchor; + DelRight(); + } + } + } + + mxDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr); + // #108205# Set cursor to remembered position. SetCursor(&aTmpPt); |