sw/qa/extras/uiwriter/uiwriter2.cxx |   57 ++++++++++++++++++++++++++++++++++++
 sw/source/core/doc/docnum.cxx       |    3 +
 2 files changed, 59 insertions(+), 1 deletion(-)

New commits:
commit be76b5c8a6599af6bbe93f7a5f4a612766048e4d
Author:     László Németh <[email protected]>
AuthorDate: Wed Jan 6 18:10:39 2021 +0100
Commit:     Gabor Kelemen <[email protected]>
CommitDate: Mon Jun 28 13:15:36 2021 +0200

    tdf#39721 sw change tracking: fix move down
    
    When moving list items by Move Down (see Bullets
    and Numbering toolbar) to a non-content node (e.g.
    tables, images or end of the document), tracked
    deletions of the inserted paragraphs reappeared
    as non-deleted text.
    
    Note: disable unit test on Windows because of
    a not reproducable problem of the Jenkins build
    (moreover, reverting the patch, and modifying the
    unit test according to the revert has still resulted
    the same problem on the Windows test machine).
    
    Change-Id: I3fb49061a81f832e1070da0f78cf7c5b3bd7d2c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108888
    Tested-by: Jenkins
    Reviewed-by: László Németh <[email protected]>
    (cherry picked from commit b5ab4836c03e9428aff6a48843f2a054ceff0f85)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117978
    Tested-by: Gabor Kelemen <[email protected]>
    Reviewed-by: Gabor Kelemen <[email protected]>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 185187cfbccc..c7f20c586327 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -602,6 +602,63 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf131912)
     CPPUNIT_ASSERT_EQUAL(OUString("foo"), pWrtShell->GetCursor()->GetText());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf39721)
+{
+// FIXME: disabled on Windows because of a not reproducable problem (not 
related to the patch)
+#if !defined(_WIN32)
+    // check move down with redlining
+    load(DATA_DIRECTORY, "tdf39721.fodt");
+
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+
+    //turn on red-lining and show changes
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    pDoc->getIDocumentRedlineAccess().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()));
+
+    // store original text of the document for checking Undo
+    OUString sOrigText(pTextDoc->getText()->getString());
+
+    // first paragraph is "Lorem ipsum" with deleted "m ips"
+    CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsum"), 
getParagraph(1)->getString());
+
+    // move down first paragraph with change tracking
+    dispatchCommand(mxComponent, ".uno:MoveDown", {});
+
+    // deletion isn't rejected
+    CPPUNIT_ASSERT_EQUAL(OUString("Loremm"), getParagraph(3)->getString());
+
+    // Undo and repeat it with the second paragraph
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+
+    CPPUNIT_ASSERT_EQUAL(sOrigText, pTextDoc->getText()->getString());
+
+    // second paragraph is "dolor sit" with deleted "lor "
+    CPPUNIT_ASSERT_EQUAL(OUString("dolor sit"), getParagraph(2)->getString());
+
+    // move down second paragraph with change tracking
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+
+    pWrtShell->Up(/*bSelect=*/false);
+    pWrtShell->Down(/*bSelect=*/false);
+
+    dispatchCommand(mxComponent, ".uno:MoveDown", {});
+
+    // This was "dolor sit" (rejecting tracked deletion)
+    CPPUNIT_ASSERT_EQUAL(OUString("dolsit"), getParagraph(4)->getString());
+
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+
+    CPPUNIT_ASSERT_EQUAL(sOrigText, pTextDoc->getText()->getString());
+#endif
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf54819)
 {
     load(DATA_DIRECTORY, "tdf54819.fodt");
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index d84574375112..620c5a2034d7 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -2141,6 +2141,7 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, tools::Long 
const nOffset,
             rOrigPam.GetPoint()->nContent.Assign( rOrigPam.GetContentNode(), 0 
);
 
             bool bDelLastPara = !aInsPos.nNode.GetNode().IsContentNode();
+            sal_uLong nOrigIdx = aIdx.GetIndex();
 
             /* When copying to a non-content node Copy will
                insert a paragraph before that node and insert before
@@ -2195,7 +2196,7 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, tools::Long 
const nOffset,
                     {
                         SwPaM pam(*pRedline, nullptr);
                         sal_uLong const nCurrentOffset(
-                            aIdx.GetIndex() + 1 - 
aPam.Start()->nNode.GetIndex());
+                            nOrigIdx - aPam.Start()->nNode.GetIndex());
                         pam.GetPoint()->nNode += nCurrentOffset;
                         
pam.GetPoint()->nContent.Assign(pam.GetPoint()->nNode.GetNode().GetContentNode(),
 pam.GetPoint()->nContent.GetIndex());
                         pam.GetMark()->nNode += nCurrentOffset;
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to