sw/qa/extras/uiwriter/uiwriter5.cxx           |   33 ++++++++++++++++++++++++++
 sw/source/core/doc/DocumentRedlineManager.cxx |    3 ++
 2 files changed, 36 insertions(+)

New commits:
commit 59952bf9b69b856ece35d03df06991c39adca267
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Jun 9 12:22:17 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Jun 12 12:19:17 2023 +0200

    tdf#155747 sw tracked table column: fix crash at table selection
    
    Selecting tracked columns and accepting their deletion resulted
    crashing because of the outdated table cursor in IsCursorInTable()
    call of UpdateTableStyleFormatting(). Remove table cursor before
    calling DeleteCol().
    
    Regression from commit d1004cdd6a445ae73673b0ca360ae034b0ec09f2
    "tdf#150673 sw offapi: add change tracking of table column deletion".
    
    Change-Id: I47f4db11bd7ce4ad851c0658eec3e12ce4fdf4a7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152792
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit fb52ae0386df9ecbfc5ddcf981fe597884d628d0)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152816

diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index dc2506881c19..88868f8086c2 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -2556,6 +2556,39 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testRedlineTableColumnDeletion)
     assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf155747)
+{
+    // load a table, and delete the first column with enabled change tracking:
+    // now the column is not deleted silently, but keeps the deleted cell 
content,
+    // and only accepting it will result the deletion of the table column.
+    createSwDoc("tdf118311.fodt");
+    SwDoc* pDoc = getSwDoc();
+
+    // 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()));
+
+    // delete table column with enabled change tracking
+    // (HasTextChangesOnly property of the cell will be false)
+    dispatchCommand(mxComponent, ".uno:DeleteColumns", {});
+
+    // select table
+    dispatchCommand(mxComponent, ".uno:SelectTable", {});
+
+    // Without the fix in place, this test would have crashed here
+    dispatchCommand(mxComponent, ".uno:AcceptTrackedChange", {});
+
+    // check removed column
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 1);
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTdf150673_RedlineTableColumnDeletionWithExport)
 {
     // load a table, and delete the first column with enabled change tracking:
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index ac0bfe547e90..d9148ce723f3 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -22,6 +22,7 @@
 #include <txtfrm.hxx>
 #include <doc.hxx>
 #include <docsh.hxx>
+#include <wrtsh.hxx>
 #include <fmtfld.hxx>
 #include <frmtool.hxx>
 #include <IDocumentUndoRedo.hxx>
@@ -467,6 +468,8 @@ namespace
             SwCursor aCursor( *pPos, nullptr );
             if ( pBox->IsEmpty() )
             {
+                // tdf#155747 remove table cursor
+                pPos->GetDoc().GetDocShell()->GetWrtShell()->EnterStdMode();
                 // TODO check the other cells of the column
                 // before removing the column
                 pPos->GetDoc().DeleteCol( aCursor );

Reply via email to