From 74650680788dc076a37d2fe4d5f9237c450807d0 Mon Sep 17 00:00:00 2001 From: László Németh Date: Tue, 5 Oct 2021 10:44:36 +0200 Subject: tdf#144748 sw: fix crash at Undo of deletion with empty table rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a table with empty rows is part of a bigger deletion, Undo of the deletion resulted a crash, because the deletion created extra redlines for the empty rows within the bigger redline. Regression from commit 9994120c8d0fe8c5a029390ad7411b99c18ff5c9 "tdf#144347 sw: fix tracked deletion of table with tracked content". See also commit 99059a1ececa3621c2fe46fabdd79eed9d626c42 "tdf#143359 sw: track deletion of empty table rows". Change-Id: I0e33e169c1ffe60022a6b66a6d70fdd9c0a9332a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123091 Tested-by: Jenkins Reviewed-by: László Németh --- sw/qa/extras/uiwriter/data/tdf144748.fodt | 82 +++++++++++++++++++++++++++++++ sw/qa/extras/uiwriter/uiwriter2.cxx | 44 +++++++++++++++++ sw/source/core/docnode/ndtbl1.cxx | 4 +- 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/uiwriter/data/tdf144748.fodt (limited to 'sw') diff --git a/sw/qa/extras/uiwriter/data/tdf144748.fodt b/sw/qa/extras/uiwriter/data/tdf144748.fodt new file mode 100644 index 000000000000..4da444cf03b3 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf144748.fodt @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a + + + b + + + c + + + + + + + + + + + + + + + + d + + + e + + + f + + + + + g + + + h + + + i + + + + + + + + diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 4a273afa49a1..9765e83cecf4 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -4551,6 +4551,50 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf143215) CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRows()->getCount()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf144748) +{ + // load a table with an empty row, and an empty line before the table + // (to allow the easy selection of the full text with the table) + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf144748.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())); + + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + // there is a table in the text + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + // delete full text with the table and check Undo + + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:Delete", {}); + // this crashed LibreOffice + dispatchCommand(mxComponent, ".uno:Undo", {}); + + // redo and check redline usage + + dispatchCommand(mxComponent, ".uno:Redo", {}); + SwEditShell* const pEditShell(pDoc->GetEditShell()); + // This was 2 (bad extra redline for the empty row of the deleted table) + CPPUNIT_ASSERT_EQUAL(static_cast(1), pEditShell->GetRedlineCount()); + + // accept deletion of the text, including the table with the empty row + + IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess()); + rIDRA.AcceptAllRedline(true); + + // no table left in the text + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf128335) { // Load the bugdoc, which has 3 textboxes. diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx index 7e9a437aed94..8a0455eabcfe 100644 --- a/sw/source/core/docnode/ndtbl1.cxx +++ b/sw/source/core/docnode/ndtbl1.cxx @@ -572,7 +572,9 @@ void SwDoc::SetRowNotTracked( const SwCursor& rCursor, const SvxPrintItem &rNew, ::lcl_ProcessRowAttr( aFormatCmp, pLn, rNew ); // as a workaround for the rows without text content, // add a redline with invisible text CH_TXT_TRACKED_DUMMY_CHAR - if (pLn->IsEmpty()) + // (unless the table is part of a bigger deletion, where the + // new redline can cause a problem) + if (!bAll && pLn->IsEmpty()) { SwNodeIndex aInsPos( *(pLn->GetTabBoxes()[0]->GetSttNd()), 1 ); RedlineFlags eOld = getIDocumentRedlineAccess().GetRedlineFlags(); -- cgit