Procházet zdrojové kódy

Recalculate table geometry on each table column removal.

Maciej Gołaszewski před 5 roky
rodič
revize
70dfc24681

+ 1 - 1
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -76,7 +76,7 @@ export default class RemoveColumnCommand extends Command {
 				removedColumnIndex >= removedColumnIndexes.first;
 				removedColumnIndex--
 			) {
-				for ( const { cell, column, colspan } of tableMap ) {
+				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 );

+ 23 - 0
packages/ckeditor5-table/tests/commands/removecolumncommand.js

@@ -324,6 +324,29 @@ describe( 'RemoveColumnCommand', () => {
 					[ '10', '[]14' ]
 				], { headingColumns: 1 } ) );
 			} );
+
+			it( 'should properly calculate truncated colspans', () => {
+				setData( model, modelTable( [
+					[ { contents: '00', colspan: 3 } ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ]
+				] ) );
+
+				const tableSelection = editor.plugins.get( TableSelection );
+				const modelRoot = model.document.getRoot();
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 1 ] )
+				);
+
+				command.execute();
+
+				assertEqualMarkup( getData( model ), modelTable( [
+					[ '00' ],
+					[ '[]12' ],
+					[ '22' ]
+				] ) );
+			} );
 		} );
 
 		it( 'should change heading columns if removing a heading column', () => {