tdf#145066 sw change tracking: fix bad deletion at Move Up/Down

In Show Changes mode, moving a list item over
a deleted list item resulted the bad deletion
of the next adjacent paragraph, too.

Note: For manual testing with a non assert build,
put cursor in list item 2, click on Move Down once,
Move Up twice to show the bad deletion.

See also b5ab4836c03e9428aff6a48843f2a054ceff0f85
"tdf#39721 sw change tracking: fix move down".

Change-Id: Ie4dd1089dea4ed7068db94b134cd31881463c9ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123378
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit bcc06060bb286bd71a8fd1707eb499c8d2a88b69)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123411
Tested-by: Jenkins
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index c6c205a..92393ab 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -947,6 +947,38 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf39721)
#endif
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf145066_bad_paragraph_deletion)
{
    // check move down with redlining: jumping over a deleted paragraph
    // resulted bad deletion of the not deleted adjacent paragraph in Show Changes mode
    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf39721.fodt");

    //turn on red-lining and show changes
    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()));

    // Three paragraphs (list items)
    CPPUNIT_ASSERT_EQUAL(3, getParagraphs());

    // move down once and move up two times second paragraph with change tracking
    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
    pWrtShell->Down(/*bSelect=*/false);
    dispatchCommand(mxComponent, ".uno:MoveDown", {});
    dispatchCommand(mxComponent, ".uno:MoveUp", {});
    dispatchCommand(mxComponent, ".uno:MoveUp", {});

    // accept all changes
    dispatchCommand(mxComponent, ".uno:AcceptAllTrackedChanges", {});

    // This was 2 (bad deletion of the first paragraph)
    CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
}

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 9546120..87d60dba 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -2177,9 +2177,11 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, tools::Long const nOffset,
                {
                    break;
                }
                if (pRedline->GetType() == RedlineType::Delete)
                if (pRedline->GetType() == RedlineType::Delete &&
                    // tdf#145066 skip full-paragraph deletion which was jumped over
                    // in Show Changes mode to avoid of deleting an extra row
                    *aPam.Start() <= *pRedline->Start())
                {
                    assert(*aPam.Start() <= *pRedline->Start()); // caller's fault
                    SwRangeRedline* pNewRedline;
                    {
                        SwPaM pam(*pRedline, nullptr);