sw/qa/extras/uiwriter/uiwriter2.cxx |   46 ++++++++++++++++++++++++++++++++++++
 sw/source/core/undo/undel.cxx       |    5 +++
 2 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit 6f20bcb152948a24dbe40ca2e6c4ecef2bebf853
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Mar 7 15:57:09 2022 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Mar 7 17:22:40 2022 +0100

    tdf#147310 sw_redlinehide: recreate frames for whole table deleted
    
    SwUndoDelete calls MakeFrames with end being end node of the table, but
    it needs to be the following node (with a frame).
    
    (regression from commit 723728cd358693b8f4bc9d913541aa4479f2bd48)
    
    Change-Id: Id0974c8349be5aef9630822738eae9462bbcb4f0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131112
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index b332046e2aab..a784061ac0d5 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1509,6 +1509,52 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf109376)
     CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf147310)
+{
+    SwDoc* pDoc = createSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+
+    // somehow bug happens only with 2 tables
+    SwInsertTableOptions tableOpt(SwInsertTableFlags::DefaultBorder, 0);
+    pWrtShell->InsertTable(tableOpt, 1, 1);
+    pWrtShell->InsertTable(tableOpt, 1, 1);
+
+    pWrtShell->SttEndDoc(/*bStart=*/true);
+
+    pWrtShell->DeleteRow(false);
+    pWrtShell->DeleteRow(false);
+
+    {
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        assertXPath(pXmlDoc, "/root/page/body/tab", 0);
+        discardDumpedLayout();
+    }
+    pWrtShell->Undo();
+    // this did not create frames for the table
+    pWrtShell->Undo();
+    {
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        // there are 2 tables
+        assertXPath(pXmlDoc, "/root/page/body/tab", 2);
+        discardDumpedLayout();
+    }
+    pWrtShell->Redo();
+    pWrtShell->Redo();
+    {
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        assertXPath(pXmlDoc, "/root/page/body/tab", 0);
+        discardDumpedLayout();
+    }
+    pWrtShell->Undo();
+    pWrtShell->Undo();
+    {
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        // there are 2 tables
+        assertXPath(pXmlDoc, "/root/page/body/tab", 2);
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf64242_optimizeTable)
 {
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf64242_optimizeTable.odt");
diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx
index 0ea396fc154b..1d75e677f9d8 100644
--- a/sw/source/core/undo/undel.cxx
+++ b/sw/source/core/undo/undel.cxx
@@ -1138,7 +1138,10 @@ void SwUndoDelete::UndoImpl(::sw::UndoRedoContext & 
rContext)
         // don't include end node in the range: it may have been merged already
         // by the start node, or it may be merged by one of the moved nodes,
         // but if it isn't merged, its current frame(s) should be good...
-        SwNodeIndex const end(rDoc.GetNodes(), m_bDelFullPara ? 
delFullParaEndNode : m_nEndNode);
+        SwNodeIndex const end(rDoc.GetNodes(), m_bDelFullPara
+            ? delFullParaEndNode
+            // tdf#147310 SwDoc::DeleteRowCol() may delete whole table - end 
must be node following table!
+            : (m_nEndNode + (rDoc.GetNodes()[m_nSttNode]->IsTableNode() && 
rDoc.GetNodes()[m_nEndNode]->IsEndNode() ? 1 : 0)));
         ::MakeFrames(&rDoc, start, end);
     }
 

Reply via email to