8
0
Эх сурвалжийг харах

Merge pull request #15 from ckeditor/t/14

Added options object to _doExecute method.
Piotrek Koszuliński 9 жил өмнө
parent
commit
e44bb91389

+ 8 - 3
packages/ckeditor5-list/src/listcommand.js

@@ -60,9 +60,14 @@ export default class ListCommand extends Command {
 	}
 
 	/**
-	 * @inheritDoc
+	 * Executes command.
+	 *
+	 * @protected
+	 * @param {Object} [options] Options for executed command.
+	 * @param {engine.model.Batch} [options.batch] Batch to collect all the change steps.
+	 * New batch will be created if this option is not set.
 	 */
-	_doExecute() {
+	_doExecute( options = {} ) {
 		const document = this.editor.document;
 		const blocks = getSelectedBlocks( document.selection, document.schema );
 
@@ -71,7 +76,7 @@ export default class ListCommand extends Command {
 		// If we are turning off items, we are going to rename them to paragraphs.
 
 		document.enqueueChanges( () => {
-			const batch = document.batch();
+			const batch = options.batch || document.batch();
 
 			// If part of a list got turned off, we need to handle (outdent) all of sub-items of the last turned-off item.
 			// To be sure that model is all the time in a good state, we first fix items below turned-off item.

+ 12 - 0
packages/ckeditor5-list/tests/listcommand.js

@@ -107,6 +107,18 @@ describe( 'ListCommand', () => {
 	} );
 
 	describe( '_doExecute', () => {
+		describe( 'custom options', () => {
+			it( 'should use provided batch', () => {
+				const batch = editor.document.batch();
+
+				expect( batch.deltas.length ).to.equal( 0 );
+
+				command._doExecute( { batch } );
+
+				expect( batch.deltas.length ).to.be.above( 0 );
+			} );
+		} );
+
 		describe( 'collapsed selection', () => {
 			it( 'should rename closest block to listItem and set correct attributes', () => {
 				setData( doc, '<paragraph>fo[]o</paragraph>' );