summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2021-03-11 23:44:06 +0800
committerMichael Stahl <michael.stahl@allotropia.de>2021-03-17 11:00:44 +0100
commiteeeb3a422e25c22201e1325154f1913df3942f2a (patch)
treeb520e2cb7376d21e5ec811302499a7161856bf5c /svx
parentb6e705ec690b9911ce44f3e6cb1273737449f186 (diff)
tdf#136956 reorder undo actions in removeColumns
and removeRows. Inside the removeColumns and removeRows, undo actions are added first, and then cell spans are updated to reflect the removed columns or rows. Once undo the cell spans they become immediately invalid because the rows or columns are already removed, hence cause Impress to crash. Change-Id: I9d8641bdad43026eca03cbeaaa3a5907b516304f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112355 Tested-by: Jenkins Reviewed-by: Mark Hung <marklh9@gmail.com> (cherry picked from commit f3f7cc53efda828af8897fa45fa2a8f18cf3b48b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112526 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/table/tablemodel.cxx61
1 files changed, 35 insertions, 26 deletions
diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx
index d7d04191163c..993535a52ec7 100644
--- a/svx/source/table/tablemodel.cxx
+++ b/svx/source/table/tablemodel.cxx
@@ -694,24 +694,6 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
{
rModel.BegUndo( SvxResId(STR_UNDO_COL_DELETE) );
rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
-
- TableModelRef xThis( this );
- ColumnVector aRemovedCols( nCount );
- sal_Int32 nOffset;
- for( nOffset = 0; nOffset < nCount; ++nOffset )
- {
- aRemovedCols[nOffset] = maColumns[nIndex+nOffset];
- }
-
- CellVector aRemovedCells( nCount * nRows );
- CellVector::iterator aCellIter( aRemovedCells.begin() );
- for( sal_Int32 nRow = 0; nRow < nRows; ++nRow )
- {
- for( nOffset = 0; nOffset < nCount; ++nOffset )
- (*aCellIter++) = getCell( nIndex + nOffset, nRow );
- }
-
- rModel.AddUndo( std::make_unique<RemoveColUndo>( xThis, nIndex, aRemovedCols, aRemovedCells ) );
}
// only rows before and inside the removed rows are considered
@@ -758,6 +740,29 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
}
}
+ // We must not add RemoveColUndo before we make cell spans correct, otherwise we
+ // get invalid cell span after undo.
+ if( bUndo )
+ {
+ TableModelRef xThis( this );
+ ColumnVector aRemovedCols( nCount );
+ sal_Int32 nOffset;
+ for( nOffset = 0; nOffset < nCount; ++nOffset )
+ {
+ aRemovedCols[nOffset] = maColumns[nIndex+nOffset];
+ }
+
+ CellVector aRemovedCells( nCount * nRows );
+ CellVector::iterator aCellIter( aRemovedCells.begin() );
+ for( sal_Int32 nRow = 0; nRow < nRows; ++nRow )
+ {
+ for( nOffset = 0; nOffset < nCount; ++nOffset )
+ (*aCellIter++) = getCell( nIndex + nOffset, nRow );
+ }
+
+ rModel.AddUndo( std::make_unique<RemoveColUndo>( xThis, nIndex, aRemovedCols, aRemovedCells ) );
+ }
+
// now remove the columns
remove_range<ColumnVector,ColumnVector::iterator>( maColumns, nIndex, nCount );
while( nRows-- )
@@ -862,14 +867,6 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount )
{
rModel.BegUndo( SvxResId(STR_UNDO_ROW_DELETE) );
rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
-
- TableModelRef xThis( this );
-
- RowVector aRemovedRows( nCount );
- for( sal_Int32 nOffset = 0; nOffset < nCount; ++nOffset )
- aRemovedRows[nOffset] = maRows[nIndex+nOffset];
-
- rModel.AddUndo( std::make_unique<RemoveRowUndo>( xThis, nIndex, aRemovedRows ) );
}
// only rows before and inside the removed rows are considered
@@ -916,6 +913,18 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount )
}
}
+ if( bUndo )
+ {
+ TableModelRef xThis( this );
+
+ RowVector aRemovedRows( nCount );
+ for( sal_Int32 nOffset = 0; nOffset < nCount; ++nOffset )
+ aRemovedRows[nOffset] = maRows[nIndex+nOffset];
+
+ // We must not RemoveRowUndo before we make cell spans correct, otherwise we
+ // get invalid cell span after undo.
+ rModel.AddUndo( std::make_unique<RemoveRowUndo>( xThis, nIndex, aRemovedRows ) );
+ }
// now remove the rows
remove_range<RowVector,RowVector::iterator>( maRows, nIndex, nCount );