[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 3 14:35:25 UTC 2019


 sw/qa/extras/uiwriter/uiwriter2.cxx |   13 +++++++++++
 sw/source/uibase/wrtsh/delete.cxx   |   40 ++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

New commits:
commit 86fd893e32ef7a737b2c4b60e0938146b102fc07
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 3 14:05:05 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jul 3 16:34:19 2019 +0200

    sw comments on frames: delete comment of frame when deleting frame
    
    Also group the two actions together, so only 1 undo action is visible to
    the user, not 2.
    
    Change-Id: Idba5a63b1653e96db4f9567a38b3f4ca740eb1df
    Reviewed-on: https://gerrit.libreoffice.org/75045
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

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);
 


More information about the Libreoffice-commits mailing list