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 14c0f2cd140da66d38a8282332f2cb734bb74e39
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Jan 8 01:28:36 2024 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Jan 8 13:20:11 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>

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 2cfcc2066c41..4aebc11b237a 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>
@@ -241,6 +243,62 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf146962)
     assertXPath(pXmlDoc, "/root/page[1]/body/tab/row"_ostr, 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"_ostr, 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 );
             }

Reply via email to