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".
Change-Id: Ifc2a7f41a57f413d27d9b464a0e464643d15f404
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138772
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 775e347..8b66108 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -3661,6 +3661,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()->GetPoint()->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()->GetPoint()->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()->GetPoint()->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()->GetPoint()->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()->GetPoint()->GetNode();
CPPUNIT_ASSERT_EQUAL(OUString("Row 2"), rNode5.GetTextNode()->GetText());
// delete the second row
pWrtShell->DeleteRow();
SwNode& rNode7 = pWrtShell->GetCursor()->GetPoint()->GetNode();
CPPUNIT_ASSERT_EQUAL(OUString("Row 3"), rNode7.GetTextNode()->GetText());
// delete the third, i.e. last row
pWrtShell->DeleteRow();
SwNode& rNode8 = pWrtShell->GetCursor()->GetPoint()->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 ef6f558c..35655fe 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -416,6 +416,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 );
@@ -428,6 +438,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 );