sw/qa/extras/uiwriter/uiwriter5.cxx |   45 ++++++++++++++++++++++++++++++++++++
 sw/source/core/table/swtable.cxx    |    8 +++++-
 2 files changed, 52 insertions(+), 1 deletion(-)

New commits:
commit c809867f3ee92a8eb36cbab840bd6d6c5b3b1c26
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Oct 14 17:47:59 2022 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Sat Oct 15 08:38:11 2022 +0200

    tdf#150976 sw: fix tracked deletion of row with nested table
    
    Rows lost their tracked deletion if one of their cells
    started with a nested table.
    
    Follow-up to commit 0140fd6501c2322cffddaaa14b49137009ffcae4
    "tdf#151478 sw: fix row/column selection at nested table"
    and commit 3442a46995f967dbd4c99797f7f13794912f0f58
    "tdf#47979 sw: test row & column selection with mouse".
    
    Change-Id: I39c291c13c5c5111d7f325f128090ee74a5e0845
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141382
    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/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index cc132640c2b1..ab457a51171e 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -38,6 +38,7 @@
 #include <sfx2/dispatch.hxx>
 #include <comphelper/lok.hxx>
 #include <txtfrm.hxx>
+#include <tabfrm.hxx>
 #include <view.hxx>
 #include <cmdid.h>
 #include <AnnotationWin.hxx>
@@ -1853,6 +1854,50 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testRedlineTableRowDeletion)
     assertXPath(pXmlDoc, "//page[1]//body/tab", 0);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf150976)
+{
+    // load a 1-row table, and delete the row with track changes
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "select-row.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()));
+
+    // check table
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    // nested table in the last cell
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell[2]/tab");
+
+    // delete table row with enabled change tracking
+    dispatchCommand(mxComponent, ".uno:DeleteRows", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+
+    // deleted text content
+    SwEditShell* const pEditShell(pDoc->GetEditShell());
+    // This was 1 before fixing tdf#151478 (testSelectRowWithNestedTable)
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(3), 
pEditShell->GetRedlineCount());
+
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    SwFrame* pPage = pLayout->Lower();
+    SwFrame* pBody = pPage->GetLower();
+    SwFrame* pTable = pBody->GetLower();
+    CPPUNIT_ASSERT(pTable->IsTabFrame());
+
+    SwTabFrame* pTabFrame = static_cast<SwTabFrame*>(pTable);
+
+    // This was false (not deleted row)
+    CPPUNIT_ASSERT(pTabFrame->GetTable()->HasDeletedRow());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testSelectRowWithNestedTable)
 {
     // load a 1-row table, and select the row
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 093330ef9fee..9e4c1b066a5d 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1672,7 +1672,10 @@ SwRedlineTable::size_type 
SwTableLine::UpdateTextChangesOnly(
                         {
                             // plain text between the delete redlines
                             if ( pPreviousDeleteRedline &&
-                                *pPreviousDeleteRedline->End() < 
*pRedline->Start() )
+                                *pPreviousDeleteRedline->End() < 
*pRedline->Start() &&
+                                // in the same section, i.e. not in a nested 
table
+                                
pPreviousDeleteRedline->End()->nNode.GetNode().StartOfSectionNode() ==
+                                    
pRedline->Start()->nNode.GetNode().StartOfSectionNode() )
                             {
                                 bPlainTextInLine = true;
                             }
@@ -1698,6 +1701,9 @@ SwRedlineTable::size_type 
SwTableLine::UpdateTextChangesOnly(
 
             // there is text content outside of redlines: not a deletion
             if ( !bInsertion && ( !bHasRedlineInBox || ( 
pPreviousDeleteRedline &&
+                 // in the same cell, i.e. not in a nested table
+                 
pPreviousDeleteRedline->End()->nNode.GetNode().StartOfSectionNode() ==
+                      aCellEnd.GetNode().StartOfSectionNode()  &&
                  ( pPreviousDeleteRedline->End()->GetNode() < 
aCellEnd.GetNode() ||
                    pPreviousDeleteRedline->End()->GetContentIndex() <
                            aCellEnd.GetNode().GetContentNode()->Len() ) ) ) )

Reply via email to