sw/qa/extras/uiwriter/uiwriter3.cxx |   70 ++++++++++++++++++++++++++++++++++++
 sw/source/core/frmedt/fetab.cxx     |   23 +++++++++++
 2 files changed, 93 insertions(+)

New commits:
commit 6b86e529fb6681bbd8207ee7f3d9e57cb2e55502
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Aug 24 17:10:56 2022 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Aug 25 19:05:18 2022 +0200

    tdf#150576 sw: fix cursor pos deleting at rows deleted already
    
    Instead of jumping in the start of the document, set cursor
    after (or deleting the last row, before) the rows deleted
    already in Hide Changes mode with enabled change tracking.
    
    Regression from commit a74c51025fa4519caaf461492e4ed8e68bd34885
    "tdf#146962 sw: hide deleted row at deletion in Hide Changes".
    
    Follow-up to commit 189aa05c6ea17a8e823b4eab18ea0d1131d9d73e
    "tdf#148849 sw: fix cursor pos at tracked DeleteRow in Hide Changes".
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter3.cxx
    
    Change-Id: Ifc2a7f41a57f413d27d9b464a0e464643d15f404
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138772
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138786
    Tested-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx 
b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 9479e34858bd..6d93e784f394 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -3564,6 +3564,76 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf148849)
     CPPUNIT_ASSERT_EQUAL(OUString("Row 2"), rNode.GetTextNode()->GetText());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf150576)
+{
+    // load a document with a table and an empty paragraph before the table
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf148849.fodt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // record changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | 
RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    // hide changes
+    dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {});
+    CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
+
+    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+
+    // Check deletion of the first row, if the second row deleted already
+
+    // put cursor in the second table row
+    pWrtShell->Down(/*bSelect=*/false, /*nCount=*/2);
+    SwNode& rNode = pWrtShell->GetCursor()->GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Row 2"), rNode.GetTextNode()->GetText());
+
+    // delete the second table row
+    pWrtShell->DeleteRow();
+
+    // check cursor position (row 3)
+    SwNode& rNode2 = pWrtShell->GetCursor()->GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Row 3"), rNode2.GetTextNode()->GetText());
+
+    // put cursor in the first row
+    pWrtShell->Up(/*bSelect=*/false, /*nCount=*/1);
+    SwNode& rNode3 = pWrtShell->GetCursor()->GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("12"), rNode3.GetTextNode()->GetText());
+
+    // delete the first row
+    pWrtShell->DeleteRow();
+
+    // This was empty (cursor jumped in the start of the document instead of
+    // the next not deleted row)
+    SwNode& rNode4 = pWrtShell->GetCursor()->GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Row 3"), rNode4.GetTextNode()->GetText());
+
+    // Check skipping previous lines
+
+    // restore deleted rows
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    Scheduler::ProcessEventsToIdle();
+    SwNode& rNode5 = pWrtShell->GetCursor()->GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Row 2"), rNode5.GetTextNode()->GetText());
+
+    // delete the second row
+    pWrtShell->DeleteRow();
+    SwNode& rNode7 = pWrtShell->GetCursor()->GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Row 3"), rNode7.GetTextNode()->GetText());
+
+    // delete the third, i.e. last row
+    pWrtShell->DeleteRow();
+    SwNode& rNode8 = pWrtShell->GetCursor()->GetNode();
+
+    // This was empty (cursor jumped in the start of the document instead of
+    // the previous not deleted row)
+    CPPUNIT_ASSERT_EQUAL(OUString("12"), rNode8.GetTextNode()->GetText());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132603)
 {
     createSwDoc();
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index c5053080d8ff..e061bbb49b68 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -417,6 +417,16 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
             }
             SwTableBox* pNextBox = pDelLine->FindNextBox( pTableNd->GetTable(),
                                                             pDelBox );
+            // skip deleted lines in Hide Changes mode with enabled change 
tracking
+            if ( bRecordAndHideChanges )
+            {
+                SwRedlineTable::size_type nRedlinePos = 0;
+                while( pNextBox && 
pNextBox->GetUpper()->IsDeleted(nRedlinePos) )
+                    pNextBox = pNextBox->GetUpper()->FindNextBox( 
pTableNd->GetTable(),
+                                    pNextBox->GetUpper()->GetTabBoxes().back() 
);
+            }
+
+            // skip protected cells
             while( pNextBox &&
                     
pNextBox->GetFrameFormat()->GetProtect().IsContentProtected() )
                 pNextBox = pNextBox->FindNextBox( pTableNd->GetTable(), 
pNextBox );
@@ -429,6 +439,19 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
                     pDelBox = pDelBox->GetTabLines()[0]->GetTabBoxes()[0];
                 pNextBox = pDelLine->FindPreviousBox( pTableNd->GetTable(),
                                                             pDelBox );
+                // skip previous deleted lines in Hide Changes mode with 
enabled change tracking
+                if ( bRecordAndHideChanges )
+                {
+                    SwRedlineTable::size_type nRedlinePos = 0;
+                    while( pNextBox && 
pNextBox->GetUpper()->IsDeleted(nRedlinePos) )
+                    {
+                        pNextBox = pNextBox->GetUpper()->FindPreviousBox( 
pTableNd->GetTable(),
+                                        pNextBox->GetUpper()->GetTabBoxes()[0] 
);
+                        nRedlinePos = 0;
+                    }
+                }
+
+                // skip previous protected cells
                 while( pNextBox &&
                         
pNextBox->GetFrameFormat()->GetProtect().IsContentProtected() )
                     pNextBox = pNextBox->FindPreviousBox( 
pTableNd->GetTable(), pNextBox );

Reply via email to