sw/qa/extras/uiwriter/uiwriter2.cxx           |   68 ++++++++++++++++++++++++++
 sw/source/core/doc/DocumentRedlineManager.cxx |   40 ++++++++++-----
 2 files changed, 95 insertions(+), 13 deletions(-)

New commits:
commit 4b850b204fbbe13e3ed11434f262dfabe528241a
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Thu Nov 29 11:10:38 2018 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Fri Nov 30 12:26:06 2018 +0100

    tdf#119824 fix undo/redo of overlapping redlines
    
    Overlapping redlines (introduced by the
    commit 9dbf817fe5c5253fba0831aefa17575ae0ba3af1
    "handle scope of w:pPrChange and w:rPrChange properly"
    for showing tracked DOCX paragraph formatting) resulted
    losing of tracked deletion, ie. reappearing deleted
    content using Redo (reported after fixing the broken
    non-visible change tracking with overlapping redlines in
    commit 694a6389e84d5b416cde6dde2d5eaa589a0a6493
    "tdf#119019 DOCX track changes: fix invisible delete
    and insert").
    
    Change-Id: I63fde7e89afde99cff242968d34cc70455c5c3c2
    Reviewed-on: https://gerrit.libreoffice.org/64218
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 66ef3ede1721..f90b1846967d 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -19,6 +19,7 @@
 #include <swdtflvr.hxx>
 #include <wrtsh.hxx>
 #include <redline.hxx>
+#include <UndoManager.hxx>
 
 namespace
 {
@@ -36,6 +37,7 @@ public:
     void testTdf108687_tabstop();
     void testTdf119571();
     void testTdf119019();
+    void testTdf119824();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest2);
     CPPUNIT_TEST(testRedlineMoveInsertInDelete);
@@ -45,6 +47,7 @@ public:
     CPPUNIT_TEST(testTdf108687_tabstop);
     CPPUNIT_TEST(testTdf119571);
     CPPUNIT_TEST(testTdf119019);
+    CPPUNIT_TEST(testTdf119824);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -273,6 +276,7 @@ void SwUiWriterTest2::testTdf119571()
 
 void SwUiWriterTest2::testTdf119019()
 {
+    // check handling of overlapping redlines
     load(DATA_DIRECTORY, "tdf119019.docx");
 
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
@@ -304,6 +308,70 @@ void SwUiWriterTest2::testTdf119019()
     CPPUNIT_ASSERT(!hasProperty(getRun(getParagraph(2), 1), "RedlineType"));
 }
 
+void SwUiWriterTest2::testTdf119824()
+{
+    // check handling of overlapping redlines with Redo
+    SwDoc* pDoc = createDoc("tdf119019.docx");
+
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+
+    CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique 
senectus "
+                                  "et netus et malesuada fames ac turpis 
egestas. "
+                                  "Proin pharetra nonummy pede. Mauris et 
orci."),
+                         getParagraph(3)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 
1)->getString());
+    // third paragraph has got a tracked paragraph formatting at this point
+    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
+
+    // and a tracked text deletion at the beginning of the paragraph
+    CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique 
senectus "),
+                         getRun(getParagraph(3), 3)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 
2)->getString());
+    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 2), "RedlineType"));
+
+    // delete last word of the third paragraph to remove tracked paragraph 
formatting
+    // of this paragraph to track and show word deletion correctly.
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->EndPara(/*bSelect=*/false);
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, 
/*bBasicCall=*/false);
+    rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
+    pTransfer->Cut();
+
+    // check tracking of the new text deletion
+    CPPUNIT_ASSERT_EQUAL(OUString("orci."), getRun(getParagraph(3), 
7)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 
6)->getString());
+    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 6), "RedlineType"));
+
+    // make sure that the tracked paragraph formatting is removed (tracked 
deletion is in the second run)
+    CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique 
senectus "),
+                         getRun(getParagraph(3), 2)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 
1)->getString());
+    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
+
+    // tdf#119824 check redo
+    sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
+    rUndoManager.Undo();
+    rUndoManager.Undo();
+    rUndoManager.Redo();
+    rUndoManager.Redo();
+
+    // check again the first tracked text deletion (we lost this before the 
redo fix)
+    CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique 
senectus "),
+                         getRun(getParagraph(3), 2)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 
1)->getString());
+    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
+
+    // check redo of the new tracked text deletion
+    CPPUNIT_ASSERT_EQUAL(OUString("orci."), getRun(getParagraph(3), 
7)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 
6)->getString());
+    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 6), "RedlineType"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 7b7880bafecd..5da8c16f1877 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -637,25 +637,39 @@ namespace
             ++n;
         }
 
-        for( ; n < rArr.size(); ++n )
+        // tdf#119824 first we will accept only overlapping paragraph format 
changes
+        // in the first loop to avoid potential content changes during Redo
+        bool bHasParagraphFormatChange = false;
+        for( int m = 0 ; m < 2 && !bHasParagraphFormatChange; ++m )
         {
-            SwRangeRedline* pTmp = rArr[ n ];
-            if( pTmp->HasMark() && pTmp->IsVisible() )
+            for(SwRedlineTable::size_type o = n ; o < rArr.size(); ++o )
             {
-                if( *pTmp->End() <= *pEnd )
-                {
-                    if( (*fn_AcceptReject)( rArr, n, bCallDelete, nullptr, 
nullptr ))
-                        nCount++;
-                }
-                else
+                SwRangeRedline* pTmp = rArr[ o ];
+                if( pTmp->HasMark() && pTmp->IsVisible() )
                 {
-                    if( *pTmp->Start() < *pEnd )
+                    if( *pTmp->End() <= *pEnd )
                     {
-                        // Only revoke the partial selection
-                        if( (*fn_AcceptReject)( rArr, n, bCallDelete, pStt, 
pEnd ))
+                        if( (m > 0 || 
nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT == pTmp->GetType()) &&
+                            (*fn_AcceptReject)( rArr, o, bCallDelete, nullptr, 
nullptr ))
+                        {
+                            bHasParagraphFormatChange = true;
                             nCount++;
+                        }
+                    }
+                    else
+                    {
+                        if( *pTmp->Start() < *pEnd )
+                        {
+                            // Only revoke the partial selection
+                            if( (m > 0 || 
nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT == pTmp->GetType()) &&
+                                (*fn_AcceptReject)( rArr, o, bCallDelete, 
pStt, pEnd ))
+                            {
+                                bHasParagraphFormatChange = true;
+                                nCount++;
+                            }
+                        }
+                        break;
                     }
-                    break;
                 }
             }
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to