Bläddra i källkod

Internal: Worked around the problem that removing multiple rows resulted with multiple undo snapshots.

Marek Lewandowski 5 år sedan
förälder
incheckning
395dbc646d
1 ändrade filer med 7 tillägg och 5 borttagningar
  1. 7 5
      packages/ckeditor5-table/src/commands/removerowcommand.js

+ 7 - 5
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -57,9 +57,12 @@ export default class RemoveRowCommand extends Command {
 		const firstCell = referenceCells[ 0 ];
 		const table = firstCell.parent.parent;
 		const tableMap = [ ...new TableWalker( table, { endRow: removedRowIndexes.last } ) ];
+		const batch = this.editor.model.createBatch( 'default' );
 
-		this.editor.model.change( writer => {
-			// Temporary workaround to avoid the "model-selection-range-intersects" error.
+		// Doing multiple model.enqueueChange() calls, to get around ckeditor/ckeditor5#6391.
+		// Ideally we want to do this in a single model.change() block.
+		this.editor.model.enqueueChange( batch, writer => {
+			// This prevents the "model-selection-range-intersects" error, caused by removing row selected cells.
 			writer.setSelection( writer.createSelection( table, 'on' ) );
 		} );
 
@@ -68,8 +71,7 @@ export default class RemoveRowCommand extends Command {
 		let cellToFocus;
 
 		for ( let i = removedRowIndexes.last; i >= removedRowIndexes.first; i-- ) {
-			// Doing model change with multiple calls, to get around ckeditor/ckeditor5#6391.
-			this.editor.model.change( writer => {
+			this.editor.model.enqueueChange( batch, writer => {
 				const removedRowIndex = i;
 				this._removeRow( removedRowIndex, table, writer, tableMap );
 
@@ -77,7 +79,7 @@ export default class RemoveRowCommand extends Command {
 			} );
 		}
 
-		this.editor.model.change( writer => {
+		this.editor.model.enqueueChange( batch, writer => {
 			writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
 		} );
 	}