sw/inc/doc.hxx | 4 +++- sw/qa/extras/uiwriter/uiwriter5.cxx | 29 +++++++++++++++++++++++++++++ sw/source/core/doc/tblrwcl.cxx | 2 +- sw/source/core/docnode/ndtbl1.cxx | 35 ++++++++++++++++++++--------------- 4 files changed, 53 insertions(+), 17 deletions(-)
New commits: commit d011ae00cbfa714b9b2b4e8ca64fa18896ecde4d Author: László Németh <nem...@numbertext.org> AuthorDate: Wed Sep 7 15:22:37 2022 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Fri Sep 9 08:38:34 2022 +0200 tdf#150876 sw: track new rows inserted after a tracked row insertion New row insertions after an already tracked row insertion weren't tracked. Regression from commit b251228d2e5e2832e0a617213173e8841f5b7428 "tdf#150666 sw: allow to delete tracked table row insertions" Follow-up to commit dbc82c02eb24ec1c97c6ee32069771d8deb394f9 "tdf#143358 sw: track insertion of empty table rows". Change-Id: Ic365e70aa7808237a1bd69d0101a098ae70e8813 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139594 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 978e95d38737..4ee71e762d30 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1493,7 +1493,9 @@ public: static bool GetRowBackground( const SwCursor& rCursor, std::unique_ptr<SvxBrushItem>& rToFill ); /// rNotTracked = false means that the row was deleted or inserted with its tracked cell content /// bAll: delete all table rows without selection - void SetRowNotTracked( const SwCursor& rCursor, const SvxPrintItem &rNotTracked, bool bAll = false ); + /// bIns: insert table row + void SetRowNotTracked( const SwCursor& rCursor, + const SvxPrintItem &rNotTracked, bool bAll = false, bool bIns = false ); /// don't call SetRowNotTracked() for rows with tracked row change static bool HasRowNotTracked( const SwCursor& rCursor ); void SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet ); diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx b/sw/qa/extras/uiwriter/uiwriter5.cxx index ea2542a40044..1ea8b51bb80e 100644 --- a/sw/qa/extras/uiwriter/uiwriter5.cxx +++ b/sw/qa/extras/uiwriter/uiwriter5.cxx @@ -2086,6 +2086,35 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf150666) CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRows()->getCount()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf150666_regression) +{ + // load a table with tracked insertion of an empty row + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "TC-table-rowadd.docx"); + + // check table count + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + // check table row count + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getRows()->getCount()); + + // select the second row (tracked table row insertion) + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Down(/*bSelect=*/false); + + // insert a new table row with track changes + dispatchCommand(mxComponent, ".uno:InsertRowsAfter", {}); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTable->getRows()->getCount()); + + dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {}); + + // This was 4 (the inserted table row wasn't tracked) + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRows()->getCount()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf144748) { // load a table with an empty row, and an empty line before the table diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx index a665016a6f07..d45457e138d7 100644 --- a/sw/source/core/doc/tblrwcl.cxx +++ b/sw/source/core/doc/tblrwcl.cxx @@ -598,7 +598,7 @@ bool SwTable::InsertRow_( SwDoc* pDoc, const SwSelBoxes& rBoxes, SwPaM aPaM(*pNewTableLine->GetTabBoxes()[0]->GetSttNd(), SwNodeOffset(1)); pDoc->getIDocumentContentOperations().InsertString( aPaM, OUStringChar(CH_TXT_TRACKED_DUMMY_CHAR) ); - pDoc->SetRowNotTracked( aCursor, aSetTracking ); + pDoc->SetRowNotTracked( aCursor, aSetTracking, /*bAll=*/false, /*bIns=*/true ); } } } diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx index 0f1dac38ea25..53d925912d25 100644 --- a/sw/source/core/docnode/ndtbl1.cxx +++ b/sw/source/core/docnode/ndtbl1.cxx @@ -578,7 +578,8 @@ bool SwDoc::HasRowNotTracked( const SwCursor& rCursor ) return false; } -void SwDoc::SetRowNotTracked( const SwCursor& rCursor, const SvxPrintItem &rNew, bool bAll ) +void SwDoc::SetRowNotTracked( const SwCursor& rCursor, + const SvxPrintItem &rNew, bool bAll, bool bIns ) { SwTableNode* pTableNd = rCursor.GetPoint()->GetNode().FindTableNode(); if( !pTableNd ) @@ -601,28 +602,34 @@ void SwDoc::SetRowNotTracked( const SwCursor& rCursor, const SvxPrintItem &rNew, GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttrTable>(*pTableNd)); } + bool bInsertDummy = !bAll && !bIns && + // HasTextChangesOnly == false, i.e. a tracked row change (deletion, if bIns == false) + !rNew.GetValue(); std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; aFormatCmp.reserve( std::max( 255, static_cast<int>(aRowArr.size()) ) ); SwRedlineTable::size_type nRedlinePos = 0; for( auto pLn : aRowArr ) { - // tdf#150666 row insertion from the same author needs special handling, + // tdf#150666 deleting row insertion from the same author needs special handling, // because removing redlines of the author can result an empty line, // which doesn't contain any redline for the tracked row bool bDeletionOfOwnRowInsertion = false; - SwRedlineTable::size_type nPos = pLn->UpdateTextChangesOnly(nRedlinePos); - if ( nPos != SwRedlineTable::npos ) + if ( bInsertDummy ) { - SwDoc* pDoc = pLn->GetFrameFormat()->GetDoc(); - IDocumentRedlineAccess& rIDRA = pDoc->getIDocumentRedlineAccess(); - const SwRedlineTable& aRedlineTable = rIDRA.GetRedlineTable(); - SwRangeRedline* pTmp = aRedlineTable[ nPos ]; - if ( RedlineType::Insert == pTmp->GetType() && - rIDRA.GetRedlineAuthor() == pTmp->GetRedlineData().GetAuthor() && - pTmp->GetText()[0] == CH_TXT_TRACKED_DUMMY_CHAR ) + SwRedlineTable::size_type nPos = pLn->UpdateTextChangesOnly(nRedlinePos); + if ( nPos != SwRedlineTable::npos ) { - bDeletionOfOwnRowInsertion = true; + SwDoc* pDoc = pLn->GetFrameFormat()->GetDoc(); + IDocumentRedlineAccess& rIDRA = pDoc->getIDocumentRedlineAccess(); + const SwRedlineTable& aRedlineTable = rIDRA.GetRedlineTable(); + SwRangeRedline* pTmp = aRedlineTable[ nPos ]; + if ( RedlineType::Insert == pTmp->GetType() && + rIDRA.GetRedlineAuthor() == pTmp->GetRedlineData().GetAuthor() && + pTmp->GetText()[0] == CH_TXT_TRACKED_DUMMY_CHAR ) + { + bDeletionOfOwnRowInsertion = true; + } } } @@ -631,9 +638,7 @@ void SwDoc::SetRowNotTracked( const SwCursor& rCursor, const SvxPrintItem &rNew, // add a redline with invisible text CH_TXT_TRACKED_DUMMY_CHAR // (unless the table is part of a bigger deletion, where the // new redline can cause a problem) - if ( !bAll && - // HasTextChangesOnly == false, i.e. a tracked row insertion or deletion - !rNew.GetValue() && (pLn->IsEmpty() || bDeletionOfOwnRowInsertion ) ) + if ( bInsertDummy && (pLn->IsEmpty() || bDeletionOfOwnRowInsertion ) ) { SwNodeIndex aInsPos( *(pLn->GetTabBoxes()[0]->GetSttNd()), 1 ); RedlineFlags eOld = getIDocumentRedlineAccess().GetRedlineFlags();