sw/qa/uitest/table/tdf146145.py |   32 ++++++++++++++++++++++++++++++++
 sw/source/core/crsr/trvltbl.cxx |    2 +-
 sw/source/core/frmedt/fetab.cxx |   26 ++++++++++++++++----------
 3 files changed, 49 insertions(+), 11 deletions(-)

New commits:
commit d17b16215629ff078d5707309115233d4752f7d8
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Thu Aug 3 12:00:07 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Aug 3 14:53:59 2023 +0200

    tdf#156595 sw tracked table column: fix crash at row deletion
    
    In Hide Changes mode, deleting a row, which has
    a hidden column deletion before the first cell,
    resulted a crash because of missing cell frame/table
    cursor.
    
    Regression from commit aff269c18b9029fec992135a406dc5031927c401
    "tdf#155345 sw tracked table column: hide them in Hide Changes mode".
    
    Note: it seems, plain uiwriter testing is not enough to catch
    the problem.
    
    Change-Id: I12675ecd402d6411107b90809728454f13e60580
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155287
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/uitest/table/tdf146145.py b/sw/qa/uitest/table/tdf146145.py
index 84cda61a6cd1..55d2092ca51e 100644
--- a/sw/qa/uitest/table/tdf146145.py
+++ b/sw/qa/uitest/table/tdf146145.py
@@ -250,4 +250,36 @@ class tdf146145(UITestCase):
             xToolkit.processEventsToIdle()
             self.assertEqual(len(tables[0].getColumns()), 5)
 
+   def test_crashWithHiddenFirstTableColumn(self):
+        with 
self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as 
self.document:
+
+            # accept all tracked changes
+            self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
+            # delete first table column
+            self.xUITest.executeCommand(".uno:DeleteColumns")
+
+            # Check enabling Accept/Reject Track Change icons
+            # and Accept Change/Reject Change context menu items
+            # on table columns with tracked deletion or insertion
+
+            # enable Track Changes toolbar
+            
self.xUITest.executeCommand(".uno:AvailableToolbars?Toolbar:string=changes")
+
+            xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+            xToolkit.processEventsToIdle()
+
+            # cursor at changed text: Accept Track Change is enabled
+            self.assertTrue(self.is_enabled_Accept_Track_Change())
+
+            # hide changes
+            self.xUITest.executeCommand(".uno:ShowTrackedChanges")
+            while self.is_enabled_Accept_Track_Change():
+                time.sleep(0.1)
+            self.assertFalse(self.is_enabled_Accept_Track_Change())
+
+            # Without the fix in place, this test would have crashed here
+            self.xUITest.executeCommand(".uno:DeleteRows")
+
+            self.xUITest.executeCommand(".uno:ShowTrackedChanges")
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/crsr/trvltbl.cxx b/sw/source/core/crsr/trvltbl.cxx
index 0aaa899b5a46..689457d02863 100644
--- a/sw/source/core/crsr/trvltbl.cxx
+++ b/sw/source/core/crsr/trvltbl.cxx
@@ -128,7 +128,7 @@ bool SwCursorShell::SelTableRowOrCol( bool bRow, bool 
bRowSimple )
 {
     // check if the current cursor's SPoint/Mark are in a table
     SwFrame *pFrame = GetCurrFrame();
-    if( !pFrame->IsInTab() )
+    if( !pFrame || !pFrame->IsInTab() )
         return false;
 
     const SwTabFrame* pTabFrame = pFrame->FindTabFrame();
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 8a6a664fe206..a766596daa29 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -535,18 +535,24 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
                 if ( SwWrtShell* pWrtShell = dynamic_cast<SwWrtShell*>(this) )
                 {
                     pWrtShell->SelectTableRow();
-                    SwShellTableCursor* pTableCursor = GetTableCursor();
+                    SwCursor* pTableCursor = 
static_cast<SwCursor*>(GetTableCursor());
                     auto pStt = aBoxes[0];
                     auto pEnd = aBoxes.back();
-                    pTableCursor->DeleteMark();
-
-                    // set start and end of the selection
-                    pTableCursor->GetPoint()->Assign( 
*pEnd->GetSttNd()->EndOfSectionNode() );
-                    pTableCursor->Move( fnMoveBackward, GoInContent );
-                    pTableCursor->SetMark();
-                    pTableCursor->GetPoint()->Assign( 
*pStt->GetSttNd()->EndOfSectionNode() );
-                    pTableCursor->Move( fnMoveBackward, GoInContent );
-                    pWrtShell->UpdateCursor();
+                    if ( pTableCursor )
+                        pTableCursor->DeleteMark();
+                    else
+                        pTableCursor = GetCursor(true);
+
+                    if ( pTableCursor )
+                    {
+                        // set start and end of the selection
+                        pTableCursor->GetPoint()->Assign( 
*pEnd->GetSttNd()->EndOfSectionNode() );
+                        pTableCursor->Move( fnMoveBackward, GoInContent );
+                        pTableCursor->SetMark();
+                        pTableCursor->GetPoint()->Assign( 
*pStt->GetSttNd()->EndOfSectionNode() );
+                        pTableCursor->Move( fnMoveBackward, GoInContent );
+                        pWrtShell->UpdateCursor();
+                    }
                 }
 
                 if (pEditShell)

Reply via email to