Skip to content

Commit

Permalink
Merge pull request #6814 from ckeditor/i/6789
Browse files Browse the repository at this point in the history
Fix (table): Editor will do not crash when removing columns next to row-spanned cells. Closes #6789.
  • Loading branch information
jodator committed May 14, 2020
2 parents 056e06e + a489ed4 commit 84e3310
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/ckeditor5-table/src/tableutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ export default class TableUtils extends Plugin {
model.change( writer => {
adjustHeadingColumns( table, { first, last }, writer );

const emptyRowsIndexes = [];

for ( let removedColumnIndex = last; removedColumnIndex >= first; removedColumnIndex-- ) {
for ( const { cell, column, colspan } of [ ...new TableWalker( table ) ] ) {
// If colspaned cell overlaps removed column decrease its span.
Expand All @@ -372,11 +374,13 @@ export default class TableUtils extends Plugin {
// If the cell was the last one in the row, get rid of the entire row.
// https://github.com/ckeditor/ckeditor5/issues/6429
if ( !cellRow.childCount ) {
this.removeRows( table, { at: cellRow.index } );
emptyRowsIndexes.push( cellRow.index );
}
}
}
}

emptyRowsIndexes.reverse().forEach( row => this.removeRows( table, { at: row, batch: writer.batch } ) );
} );
}

Expand Down
14 changes: 14 additions & 0 deletions packages/ckeditor5-table/tests/tableutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,20 @@ describe( 'TableUtils', () => {
[ '21', '22' ]
] ) );
} );

it( 'should remove the column properly when multiple rows should be removed (because of to row-spans)', () => {
setData( model, modelTable( [
[ '00', { contents: '01', rowspan: 3 }, { contents: '02', rowspan: 3 } ],
[ '10' ],
[ '20' ]
] ) );

tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );

assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
[ '01', '02' ]
] ) );
} );
} );

describe( 'multiple columns', () => {
Expand Down

0 comments on commit 84e3310

Please sign in to comment.