sw/qa/extras/uiwriter/data/tdf145311.fodt |   39 ++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter2.cxx       |   35 ++++++++++++++++++++
 sw/source/core/doc/docnum.cxx             |   51 ++++++++++++++++++++++++++++++
 3 files changed, 125 insertions(+)

New commits:
commit 643bbf9e47e909b2d4acefaee791c9dd7d9e4a8d
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Nov 3 12:46:41 2021 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Nov 3 14:14:58 2021 +0100

    tdf#145311 sw track changes: fix moving over empty list item
    
    which was changed to tracked insertion.
    
    Follow-up to commit 4c982dbafdac900e233d7b68d95c9c99244defc1
    "tdf#145225 sw track changes: fix bad insert at moving".
    
    Change-Id: If3d70da71188e95b5aeea9b72e7c9de22d7c7150
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124645
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/data/tdf145311.fodt 
b/sw/qa/extras/uiwriter/data/tdf145311.fodt
new file mode 100644
index 000000000000..2ebc9d0ebf14
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf145311.fodt
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; office:version="1.2" 
office:mimetype="application/vnd.oasis.opendocument.text" 
xmlns:dc="http://purl.org/dc/elements/1.1/";>
+ <office:styles>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+  <style:default-style style:family="paragraph">
+   <style:text-properties fo:language="en" fo:country="US"/>
+  </style:default-style>
+ </office:styles>
+ <office:body>
+  <office:text>
+   <text:list xml:id="list3957351959" text:style-name="L1">
+    <text:list-item>
+     <text:p text:style-name="P1">January</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1">February</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1">March</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1"/>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1">April</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1">May</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1">June</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P1">July</text:p>
+    </text:list-item>
+   </text:list>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index b9904e0d3f3e..202c6d5855ff 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -959,6 +959,41 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testTdf145066_bad_paragraph_deletion)
                          pTextDoc->getText()->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf145311_move_over_empty_paragraphs)
+{
+    // check move up/down with redlining: jumping over an empty paragraph
+    // resulted bad insertion of the empty paragraph in Show Changes mode
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf145311.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()));
+
+    // 8 paragraphs (list items)
+    CPPUNIT_ASSERT_EQUAL(8, getParagraphs());
+
+    // move down the first item over the empty paragraph
+    for (int i = 0; i < 4; ++i)
+        dispatchCommand(mxComponent, ".uno:MoveDown", {});
+
+    SwEditShell* const pEditShell(pDoc->GetEditShell());
+    // This was 3 (bad conversion of the empty item to a tracked insertion)
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(2), 
pEditShell->GetRedlineCount());
+
+    // check move up
+
+    for (int i = 0; i < 3; ++i)
+        dispatchCommand(mxComponent, ".uno:MoveUp", {});
+
+    // This was 3 (bad conversion of the empty item to a tracked insertion)
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(2), 
pEditShell->GetRedlineCount());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf54819)
 {
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf54819.fodt");
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index c496fa9db4dd..12b23c2fbb42 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -2172,6 +2172,12 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, SwNodeOffset 
const nOffset,
 
             --aIdx; // move before insertion
 
+            // adjust empty nodes later
+            SwTextNode const*const pIsEmptyNode(nOffset < SwNodeOffset(0)
+                           ? aInsPos.nNode.GetNode().GetTextNode()
+                           : aIdx.GetNode().GetTextNode());
+            bool bIsEmptyNode = pIsEmptyNode && pIsEmptyNode->Len() == 0;
+
             getIDocumentContentOperations().CopyRange(aPam, aInsPos, 
SwCopyFlags::CheckPosInFly);
 
             // now delete all the delete redlines that were copied
@@ -2282,6 +2288,51 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, SwNodeOffset 
const nOffset,
             
aPam.GetBound(false).nContent.Assign(aPam.GetBound(false).nNode.GetNode().GetContentNode(),
 0);
             sw::UpdateFramesForAddDeleteRedline(*this, aPam);
 
+            // avoid setting empty nodes to tracked insertion
+            if ( bIsEmptyNode )
+            {
+                SwRedlineTable& rTable = 
getIDocumentRedlineAccess().GetRedlineTable();
+                SwRedlineTable::size_type nRedlPosWithEmpty =
+                    getIDocumentRedlineAccess().GetRedlinePos( 
pStt->nNode.GetNode(), RedlineType::Insert );
+                if ( SwRedlineTable::npos != nRedlPosWithEmpty )
+                {
+                    pOwnRedl = rTable[nRedlPosWithEmpty];
+                    SwPosition *pRPos = nOffset < SwNodeOffset(0) ? 
pOwnRedl->End() : pOwnRedl->Start();
+                    SwNodeIndex aIdx2 ( pRPos->nNode );
+                    SwTextNode const*const 
pEmptyNode0(aIdx2.GetNode().GetTextNode());
+                    if ( nOffset < SwNodeOffset(0) )
+                    {
+                        // move up
+                        --aIdx2;
+                        SwTextNode const*const 
pEmptyNode(aIdx2.GetNode().GetTextNode());
+                        if ( pEmptyNode && pEmptyNode->Len() == 0 )
+                        {
+                            --(pRPos->nNode);
+                            pRPos->nContent.Assign( 
aIdx2.GetNode().GetContentNode(), 0 );
+                        }
+                    }
+                    else if ( pEmptyNode0 && pEmptyNode0->Len() == 0 )
+                    {
+                        // move down
+                        ++aIdx2;
+                        SwTextNode const*const 
pEmptyNode(aIdx2.GetNode().GetTextNode());
+                        if (pEmptyNode)
+                        {
+                            ++(pRPos->nNode);
+                            pRPos->nContent.Assign( 
aIdx2.GetNode().GetContentNode(), 0 );
+                        }
+                    }
+
+                    // sort redlines, when the trimmed range results bad 
redline order
+                    if ( nRedlPosWithEmpty + 1 < rTable.size() &&
+                            *rTable[nRedlPosWithEmpty + 1] < 
*rTable[nRedlPosWithEmpty] )
+                    {
+                        rTable.Remove(nRedlPosWithEmpty);
+                        rTable.Insert(pOwnRedl);
+                    }
+                }
+            }
+
             getIDocumentRedlineAccess().SetRedlineFlags( eOld );
             GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
             getIDocumentState().SetModified();

Reply via email to