sw/qa/extras/uiwriter/uiwriter5.cxx |   76 ++++++++++++++++++++++++++++++++++++
 sw/source/core/frmedt/fetab.cxx     |    4 +
 2 files changed, 79 insertions(+), 1 deletion(-)

New commits:
commit 72cf81802b7a9c4ce64cf853a80f2660da5ee26e
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue Aug 1 13:10:07 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Aug 3 11:50:36 2023 +0200

    tdf#156544 sw tracked table column: delete empty column
    
    Empty table columns were removed without change tracking
    in Record Changes mode, too.
    
    Follow-up to commit fe43f5971dfd2a121634eea9e39c7ad0cf3f962a
    "tdf#156475 sw tracked table column: delete empty cell".
    
    Change-Id: I8154cb1c75cf793f5a60e8259a91dd779fc766e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155153
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 33058b5dc47a140516669945efbdd30ea65138a6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155187
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index 07579cc6662a..3e8babfff390 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -2701,6 +2701,82 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf155747)
     assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf156544)
+{
+    // load a table, and insert a column without change tracking,
+    // and delete the first column with the empty cell in the second row with 
change tracking
+    createSwDoc("tdf118311.fodt");
+    SwDoc* pDoc = getSwDoc();
+
+    // turn off red-lining and show changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be off",
+                           !pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // insert table column without change tracking
+    // (HasTextChangesOnly property of the cell will be false)
+    dispatchCommand(mxComponent, ".uno:InsertColumnsBefore", {});
+
+    // check table
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row[1]/cell", 3);
+
+    // turn on red-lining
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | 
RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+
+    // go to the empty column
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+
+    // delete table column with enabled change tracking
+    // (HasTextChangesOnly property of the cell will be false)
+    dispatchCommand(mxComponent, ".uno:DeleteColumns", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+
+    // This was 2 (deleted column)
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 3);
+
+    // accept the deletion of the empty column
+    dispatchCommand(mxComponent, ".uno:AcceptTrackedChange", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 2);
+
+    // test Undo/Redo
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 3);
+
+    dispatchCommand(mxComponent, ".uno:Redo", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 2);
+}
+
 #ifndef DBG_UTIL
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf149498)
 {
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index c271d975d567..8a6a664fe206 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -283,6 +283,7 @@ bool SwFEShell::DeleteCol()
     // and set IsNoTracked table box property to false
     if ( GetDoc()->GetDocShell()->IsChangeRecording() )
     {
+        bool bDeletedEmptyCell = false;
         StartUndo(SwUndoId::COL_DELETE);
         StartAllAction();
 
@@ -317,6 +318,7 @@ bool SwFEShell::DeleteCol()
                     aCursor.GetMark()->SetContent(0);
                     rIDRA.SetRedlineFlags_intern( eOld );
                     rIDCO.DeleteAndJoin( aCursor );
+                    bDeletedEmptyCell = true;
                 }
 
             }
@@ -332,7 +334,7 @@ bool SwFEShell::DeleteCol()
         // track column deletion only if there were tracked text changes
         // FIXME redline count can be the same in special cases, e.g. adding a
         // new tracked deletion with removing an own tracked insertion...
-        if ( nPrev != pEditShell->GetRedlineCount() )
+        if ( bDeletedEmptyCell || nPrev != pEditShell->GetRedlineCount() )
             return true;
     }
 

Reply via email to