sw/qa/extras/uiwriter/uiwriter2.cxx | 27 +++++++++++++++++++++++++++ sw/source/uibase/wrtsh/delete.cxx | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 5 deletions(-)
New commits: commit 976c737a6d387acaeadfe5a3f7265a5cdb9384c7 Author: László Németh <nem...@numbertext.org> AuthorDate: Mon Apr 26 09:33:45 2021 +0200 Commit: Balazs Varga <varga.bala...@nisz.hu> CommitDate: Thu Oct 21 09:38:51 2021 +0200 tdf#59463 track changes: record deletion of images Instead of deleting the image object without recording the deletion, delete the anchor point in the text to record the deletion, if Record Changes is enabled. Note: only images anchored as characters can be recorded this way, so change the anchor before the deletion, if needed. This less problem, than hidden, i.e. non-tracked deletion of images. Change-Id: I7e4bee82b76b4a26e6482a678a2a1ce432980271 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114671 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123855 Tested-by: Balazs Varga <varga.bala...@nisz.hu> Reviewed-by: Balazs Varga <varga.bala...@nisz.hu> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 7e3488b23e5b..29bbb8dbb7ba 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -3019,6 +3019,33 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageCommentAtChar) CPPUNIT_ASSERT_EQUAL(*pImageAnchor, rAnnotationMarkStart); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageDeletion) +{ + // load a document with an image anchored to paragraph in it + SwDoc* pDoc = createDoc("image.odt"); + SwView* pView = pDoc->GetDocShell()->GetView(); + + // select the image + pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON); + + // turn on red-lining and show changes + IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess()); + + rIDRA.SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete | RedlineFlags::ShowInsert); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // now delete the image with track changes + pView->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON); + + const SwRedlineTable& rTable = rIDRA.GetRedlineTable(); + // this was 0 (missing recording of deletion of images) + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338) { load(DATA_DIRECTORY, "tdf120338.docx"); diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 0dbc7eb89cc5..f9a5772a603a 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <cmdid.h> #include <wrtsh.hxx> #include <swcrsr.hxx> #include <editeng/lrspitem.hxx> @@ -416,30 +417,55 @@ bool SwWrtShell::DelRight() case SelectionType::DrawObjectEditMode: case SelectionType::DbForm: { + // Group deletion of the object and its comment together + // (also as-character anchor conversion at track changes) + mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr); + // #108205# Remember object's position. Point aTmpPt = GetObjRect().TopLeft(); // Remember the anchor of the selected object before deletion. std::unique_ptr<SwPosition> pAnchor; + RndStdIds eAnchorId = RndStdIds::FLY_AT_PARA; SwFlyFrame* pFly = GetSelectedFlyFrame(); if (pFly) { SwFrameFormat* pFormat = pFly->GetFormat(); if (pFormat) { - RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId(); + eAnchorId = pFormat->GetAnchor().GetAnchorId(); + // as-character anchor conversion at track changes + if ( IsRedlineOn() && eAnchorId != RndStdIds::FLY_AS_CHAR ) + { + SfxItemSet aSet(GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{}); + GetFlyFrameAttr(aSet); + SwFormatAnchor aAnch(RndStdIds::FLY_AS_CHAR); + aSet.Put(aAnch); + SetFlyFrameAttr(aSet); + eAnchorId = pFormat->GetAnchor().GetAnchorId(); + } if ((eAnchorId == RndStdIds::FLY_AS_CHAR || eAnchorId == RndStdIds::FLY_AT_CHAR) && pFormat->GetAnchor().GetContentAnchor()) { pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor())); + // set cursor before the anchor point + if ( IsRedlineOn() ) + *GetCurrentShellCursor().GetPoint() = *pAnchor; } } } - // Group deletion of the object and its comment together. - mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr); - - DelSelectedObj(); + // track changes: delete the anchor point of the image to record the deletion + if ( IsRedlineOn() && pAnchor && SelectionType::Graphic & nSelection + && eAnchorId == RndStdIds::FLY_AS_CHAR ) + { + OpenMark(); + SwCursorShell::Right(1, CRSR_SKIP_CHARS); + bRet = Delete(); + CloseMark( bRet ); + } + else + DelSelectedObj(); if (pAnchor) {