sw/qa/uitest/writer_tests7/tdf156900.py |   46 ++++++++++++++++++++++++++++++++
 sw/source/core/frmedt/fetab.cxx         |   28 ++++++++-----------
 2 files changed, 58 insertions(+), 16 deletions(-)

New commits:
commit 5d490133efe7a2509515ac6d85ed3db0a7988b3c
Author:     László Németh <[email protected]>
AuthorDate: Wed Sep 27 14:16:53 2023 +0200
Commit:     László Németh <[email protected]>
CommitDate: Thu Sep 28 09:37:13 2023 +0200

    tdf#156900 sw tracked table column: fix row deletion
    
    If the last deleted table column was hidden, it was
    not possible to delete the table rows.
    
    Regression from commit aff269c18b9029fec992135a406dc5031927c401
    "tdf#155345 sw tracked table column: hide them in Hide Changes mode".
    
    Change-Id: I51b78f6f5552bdba2240bf278ac1d796830a1beb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157330
    Tested-by: Jenkins
    Reviewed-by: László Németh <[email protected]>

diff --git a/sw/qa/uitest/writer_tests7/tdf156900.py 
b/sw/qa/uitest/writer_tests7/tdf156900.py
new file mode 100644
index 000000000000..545be94242f4
--- /dev/null
+++ b/sw/qa/uitest/writer_tests7/tdf156900.py
@@ -0,0 +1,46 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_url_for_data_file
+
+# Bug 156900 - no row deletion when there is a hidden last column
+
+class tdf156900(UITestCase):
+    def test_tdf156900(self):
+        with 
self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as 
self.document:
+
+            xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+
+            # accept all tracked changes
+            self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
+
+            # delete last column
+            self.xUITest.executeCommand(".uno:GoRight")
+            self.xUITest.executeCommand(".uno:GoRight")
+            self.xUITest.executeCommand(".uno:GoRight")
+            self.xUITest.executeCommand(".uno:GoRight")
+            self.xUITest.executeCommand(".uno:DeleteColumns")
+
+            # hide changes
+            self.xUITest.executeCommand(".uno:ShowTrackedChanges")
+
+            # delete first row
+            self.xUITest.executeCommand(".uno:DeleteRows")
+
+            # accept all changes
+            self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
+
+            tables = self.document.getTextTables()
+            # This was 3 (not deleted row)
+            self.assertEqual(len(tables[0].getRows()), 2)
+
+            # show changes
+            self.xUITest.executeCommand(".uno:ShowTrackedChanges")
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 59b031ce772a..74b9874dc5ac 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -425,8 +425,10 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
 
     // tracked deletion: remove only textbox content,
     // and set HasTextChangesOnly table line property to false
+    SwEditShell* pEditShell = nullptr;
     if ( bRecordChanges )
     {
+        pEditShell = GetDoc()->GetEditShell();
         SvxPrintItem aHasTextChangesOnly(RES_PRINT, false);
         GetDoc()->SetRowNotTracked( *getShellCursor( false ), 
aHasTextChangesOnly );
 
@@ -436,7 +438,7 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
         // don't need to remove the row frames in Show Changes mode
         if ( !bRecordAndHideChanges )
         {
-            if (SwEditShell* pEditShell = GetDoc()->GetEditShell())
+            if ( pEditShell )
                 pEditShell->Delete(false);
 
             EndAllActionAndCall();
@@ -540,36 +542,30 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
             }
 
             // delete row content in Hide Changes mode
-            if ( bRecordAndHideChanges )
+            if ( pEditShell && bRecordAndHideChanges )
             {
-                SwEditShell* pEditShell = GetDoc()->GetEditShell();
-
-                // select the rows deleted with change tracking
-                if ( SwWrtShell* pWrtShell = dynamic_cast<SwWrtShell*>(this) )
+                // select the row deleted with change tracking cell by cell to 
handle
+                // the already deleted cells
+                SwWrtShell* pWrtShell = dynamic_cast<SwWrtShell*>(this);
+                for (SwSelBoxes::size_type nBox = 0; pWrtShell && nBox < 
aBoxes.size(); ++nBox)
                 {
                     pWrtShell->SelectTableRow();
                     SwCursor* pTableCursor = 
static_cast<SwCursor*>(GetTableCursor());
-                    auto pStt = aBoxes[0];
-                    auto pEnd = aBoxes.back();
-                    if ( pTableCursor )
-                        pTableCursor->DeleteMark();
-                    else
+                    auto pStt = aBoxes[nBox];
+                    if ( !pTableCursor )
                         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->DeleteMark();
                         pTableCursor->GetPoint()->Assign( 
*pStt->GetSttNd()->EndOfSectionNode() );
                         pTableCursor->Move( fnMoveBackward, GoInContent );
                         pWrtShell->UpdateCursor();
                     }
-                }
 
-                if (pEditShell)
                     pEditShell->Delete(false);
+                }
             }
 
             SwNodeOffset nIdx;

Reply via email to