Browse Source

Merge branch 'i/6439' into i/6546

Maciej Gołaszewski 5 years ago
parent
commit
6942372f2c

+ 4 - 2
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -92,7 +92,9 @@ export default class RemoveColumnCommand extends Command {
 	 * @param {module:engine/model/writer~Writer} writer
 	 */
 	_removeColumn( removedColumnIndex, table, writer ) {
-		for ( const { cell, column, colspan } of new TableWalker( table ) ) {
+		const tableUtils = this.editor.plugins.get( 'TableUtils' );
+
+		for ( const { cell, column, colspan } of [ ...new TableWalker( table ) ] ) {
 			// If colspaned cell overlaps removed column decrease its span.
 			if ( column <= removedColumnIndex && colspan > 1 && column + colspan > removedColumnIndex ) {
 				updateNumericAttribute( 'colspan', colspan - 1, cell, writer );
@@ -105,7 +107,7 @@ export default class RemoveColumnCommand extends Command {
 				// 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 ) {
-					writer.remove( cellRow );
+					tableUtils.removeRow( cellRow.index, table, writer );
 				}
 			}
 		}

+ 25 - 10
packages/ckeditor5-table/tests/commands/removecolumncommand.js

@@ -418,7 +418,7 @@ describe( 'RemoveColumnCommand', () => {
 			] ) );
 		} );
 
-		it( 'should work property if the rowspan is in the first column (#1)', () => {
+		it( 'should work property if the rowspan is in the first column (the other cell in row is selected)', () => {
 			setData( model, modelTable( [
 				[ { rowspan: 2, contents: '00' }, '[]01' ],
 				[ '10' ]
@@ -427,11 +427,11 @@ describe( 'RemoveColumnCommand', () => {
 			command.execute();
 
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { rowspan: 2, contents: '[]00' } ]
+				[ '[]00' ]
 			] ) );
 		} );
 
-		it( 'should work property if the rowspan is in the first column (#2)', () => {
+		it( 'should work property if the rowspan is in the first column (the cell in row below is selected)', () => {
 			setData( model, modelTable( [
 				[ { rowspan: 2, contents: '00' }, '01' ],
 				[ '[]10' ]
@@ -440,11 +440,11 @@ describe( 'RemoveColumnCommand', () => {
 			command.execute();
 
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { rowspan: 2, contents: '[]00' } ]
+				[ '[]00' ]
 			] ) );
 		} );
 
-		it( 'should work property if the rowspan is in the first column (#3)', () => {
+		it( 'should work property if the rowspan is in the first column (the cell with rowspan is selected)', () => {
 			setData( model, modelTable( [
 				[ { rowspan: 2, contents: '00[]' }, '01' ],
 				[ '10' ]
@@ -458,7 +458,7 @@ describe( 'RemoveColumnCommand', () => {
 			] ) );
 		} );
 
-		it( 'should work property if the rowspan is in the last column (#1)', () => {
+		it( 'should work property if the rowspan is in the last column (the other cell in row is selected)', () => {
 			setData( model, modelTable( [
 				[ '[]00', { rowspan: 2, contents: '01' } ],
 				[ '10' ]
@@ -467,11 +467,11 @@ describe( 'RemoveColumnCommand', () => {
 			command.execute();
 
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { rowspan: 2, contents: '[]01' } ]
+				[ '[]01' ]
 			] ) );
 		} );
 
-		it( 'should work property if the rowspan is in the last column (#2)', () => {
+		it( 'should work property if the rowspan is in the last column (the cell in row below is selected)', () => {
 			setData( model, modelTable( [
 				[ '00', { rowspan: 2, contents: '01' } ],
 				[ '[]10' ]
@@ -480,11 +480,11 @@ describe( 'RemoveColumnCommand', () => {
 			command.execute();
 
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { rowspan: 2, contents: '[]01' } ]
+				[ '[]01' ]
 			] ) );
 		} );
 
-		it( 'should work property if the rowspan is in the last column (#3)', () => {
+		it( 'should work property if the rowspan is in the last column (the cell with rowspan is selected)', () => {
 			setData( model, modelTable( [
 				[ '00', { rowspan: 2, contents: '[]01' } ],
 				[ '10' ]
@@ -497,5 +497,20 @@ describe( 'RemoveColumnCommand', () => {
 				[ '10' ]
 			] ) );
 		} );
+
+		it( 'should remove column if removing row with one column - other columns are spanned', () => {
+			setData( model, modelTable( [
+				[ '[]00', { rowspan: 2, contents: '01' }, { rowspan: 2, contents: '02' } ],
+				[ '10' ],
+				[ '20', '21', '22' ]
+			] ) );
+
+			command.execute();
+
+			assertEqualMarkup( getData( model ), modelTable( [
+				[ '[]01', '02' ],
+				[ '21', '22' ]
+			] ) );
+		} );
 	} );
 } );