Browse Source

Remove row command should create only one undo step.

Maciej Gołaszewski 5 years ago
parent
commit
d141593969

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

@@ -82,7 +82,7 @@ export default class RemoveRowCommand extends Command {
 
 				// 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 => {
+				model.enqueueChange( writer.batch, writer => {
 					updateNumericAttribute( 'headingRows', newRows, table, writer, 0 );
 				} );
 			}

+ 28 - 0
packages/ckeditor5-table/tests/commands/removerowcommand.js

@@ -311,6 +311,34 @@ describe( 'RemoveRowCommand', () => {
 					[ '[]20', '01' ]
 				] ) );
 			} );
+
+			it( 'should create one undo step (1 batch)', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ],
+					[ '10', '11' ],
+					[ '20', '21' ],
+					[ '30', '31' ]
+				], { headingRows: 3 } ) );
+
+				const createdBatches = new Set();
+
+				model.on( 'applyOperation', ( evt, args ) => {
+					const operation = args[ 0 ];
+
+					createdBatches.add( operation.batch );
+				} );
+
+				const tableSelection = editor.plugins.get( TableSelection );
+				const modelRoot = model.document.getRoot();
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 0 ] )
+				);
+
+				command.execute();
+
+				expect( createdBatches.size ).to.equal( 1 );
+			} );
 		} );
 
 		describe( 'with entire row selected', () => {