sw/qa/extras/uiwriter/data/tdf159026.docx |binary sw/qa/extras/uiwriter/uiwriter8.cxx | 58 ++++++++++++++++++++++++++++++ sw/source/core/frmedt/tblsel.cxx | 4 +- 3 files changed, 61 insertions(+), 1 deletion(-)
New commits: commit 1b79e993fefbf102466f7a0e394e71478a643896 Author: László Németh <nem...@numbertext.org> AuthorDate: Mon Jan 8 01:28:36 2024 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Wed Jan 10 15:08:45 2024 +0100 tdf#159026 sw: fix Undo crash with tracked floating table deletion In Hide Changes mode, tracked deletion of a floating table, and after that, its frame resulted a crash during Undos. Regression from commit 0c6221e1545e7b96d9df23cdc24302c28ae935b8 "tdf#148227 sw: fix Undo of tracked row deletion in Hide Changes mode". Change-Id: I3fd88a30df2739ce8a3cdc24da07684a3ac5a41b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161777 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit f5a00d9ffb8325f4b9fed21b5c96ca005e11b1bb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161758 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit de7e0bc32d3629063f13250ae3b7c9f934fba046) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161855 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/uiwriter/data/tdf159026.docx b/sw/qa/extras/uiwriter/data/tdf159026.docx new file mode 100644 index 000000000000..65bfaae3e423 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf159026.docx differ diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index 04655535c2d5..a928bea1695d 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -15,9 +15,11 @@ #include <com/sun/star/awt/FontWeight.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <IDocumentDrawModelAccess.hxx> +#include <com/sun/star/text/XTextFrame.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <com/sun/star/text/XPageCursor.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> #include <comphelper/propertysequence.hxx> #include <boost/property_tree/json_parser.hpp> #include <frameformats.hxx> @@ -236,6 +238,62 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf146962) assertXPath(pXmlDoc, "/root/page[1]/body/tab/row", 2); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf159026) +{ + // load a floating table (tables in DOCX footnotes + // imported as floating tables in Writer) + createSwDoc("tdf159026.docx"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + // enable redlining + dispatchCommand(mxComponent, ".uno:TrackChanges", {}); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + // hide changes + dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {}); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines()); + + // select table with SelectionSupplier + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); + + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<view::XSelectionSupplier> xSelSupplier(xModel->getCurrentController(), + uno::UNO_QUERY_THROW); + // select floating table (table in a frame) + xSelSupplier->select(xIndexAccess->getByIndex(0)); + + // delete table with track changes + dispatchCommand(mxComponent, ".uno:DeleteTable", {}); + + // tracked table deletion + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); + + // hidden table + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "//tab", 0); + + // delete frame + uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xIndexAccess2(xTextFramesSupplier->getTextFrames(), + uno::UNO_QUERY); + xSelSupplier->select(xIndexAccess2->getByIndex(0)); + dispatchCommand(mxComponent, ".uno:Delete", {}); + + // undo frame deletion + dispatchCommand(mxComponent, ".uno:Undo", {}); + + // undo tracked table deletion + + // This resulted crashing + dispatchCommand(mxComponent, ".uno:Undo", {}); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf147347) { // load a 2-row table, set Hide Changes mode and delete the table with change tracking diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx index 48a92366509c..ec56a5285675 100644 --- a/sw/source/core/frmedt/tblsel.cxx +++ b/sw/source/core/frmedt/tblsel.cxx @@ -2383,7 +2383,9 @@ void FndBox_::MakeFrames( SwTable &rTable ) for ( sal_uInt16 j = nStPos; j <= nEndPos; ++j ) { SwTableLine * pLine = rTable.GetTabLines()[j]; - if ( !bHideChanges || !pLine->IsDeleted(nRedlinePos) ) + if ( ( !bHideChanges || !pLine->IsDeleted(nRedlinePos) ) && + // tdf#159026 fix Undo crash with floating tables + pUpperFrame->GetUpper() ) ::lcl_InsertRow( *pLine, static_cast<SwLayoutFrame*>(pUpperFrame), pSibling ); }