Browse Source

Add batch option to TableUtils.removeRows() method to re-use it during table modifications.

Maciej Gołaszewski 5 years ago
parent
commit
ade0088b6e
1 changed files with 13 additions and 12 deletions
  1. 13 12
      packages/ckeditor5-table/src/tableutils.js

+ 13 - 12
packages/ckeditor5-table/src/tableutils.js

@@ -287,22 +287,23 @@ export default class TableUtils extends Plugin {
 		const rowsToRemove = options.rows || 1;
 
 		const last = first + rowsToRemove - 1;
+		const batch = options.batch || 'default';
 
-		model.change( writer => {
-			for ( let i = last; i >= first; i-- ) {
-				removeRow( table, i, writer );
-			}
+		const headingRows = table.getAttribute( 'headingRows' ) || 0;
 
-			const headingRows = table.getAttribute( 'headingRows' ) || 0;
+		if ( headingRows && first < headingRows ) {
+			const newRows = getNewHeadingRowsValue( first, last, headingRows );
 
-			if ( headingRows && first < headingRows ) {
-				const newRows = getNewHeadingRowsValue( first, last, headingRows );
+			// Must be done after the changes in table structure (removing rows).
+			// Otherwise the downcast converter for headingRows attribute will fail. ckeditor/ckeditor5#6391.
+			model.enqueueChange( batch, writer => {
+				updateNumericAttribute( 'headingRows', newRows, table, writer, 0 );
+			} );
+		}
 
-				// Must be done after the changes in table structure (removing rows).
-				// Otherwise the downcast converter for headingRows attribute will fail. ckeditor/ckeditor5#6391.
-				model.enqueueChange( writer.batch, writer => {
-					updateNumericAttribute( 'headingRows', newRows, table, writer, 0 );
-				} );
+		model.enqueueChange( batch, writer => {
+			for ( let i = last; i >= first; i-- ) {
+				removeRow( table, i, writer );
 			}
 		} );
 	}