Răsfoiți Sursa

Aligned code with new Batch API.

Oskar Wróbel 8 ani în urmă
părinte
comite
8f5a48130c

+ 2 - 1
packages/ckeditor5-list/src/converters.js

@@ -612,7 +612,8 @@ export function modelChangePostFixer( document ) {
 
 			// Element name is changed from list to something else. Remove useless attributes.
 			document.enqueueChanges( () => {
-				batch.removeAttribute( element, 'indent' ).removeAttribute( element, 'type' );
+				batch.removeAttribute( element, 'indent' );
+				batch.removeAttribute( element, 'type' );
 			} );
 
 			const changePos = ModelPosition.createAfter( changes.element );

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

@@ -208,7 +208,9 @@ export default class ListCommand extends Command {
 				} else if ( !turnOff && element.name != 'listItem' ) {
 					// We are turning on and the element is not a `listItem` - it should be converted to `listItem`.
 					// The order of operations is important to keep model in correct state.
-					batch.setAttribute( element, 'type', this.type ).setAttribute( element, 'indent', 0 ).rename( element, 'listItem' );
+					batch.setAttribute( element, 'type', this.type );
+					batch.setAttribute( element, 'indent', 0 );
+					batch.rename( element, 'listItem' );
 				} else if ( !turnOff && element.name == 'listItem' && element.getAttribute( 'type' ) != this.type ) {
 					// We are turning on and the element is a `listItem` but has different type - change it's type and
 					// type of it's all siblings that have same indent.

+ 21 - 17
packages/ckeditor5-list/tests/listengine.js

@@ -1543,9 +1543,10 @@ describe( 'ListEngine', () => {
 						const item2 = '<listItem indent="1" type="bulleted">d</listItem>';
 
 						modelDoc.enqueueChanges( () => {
-							modelDoc.batch()
-								.insert( ModelPosition.createAt( modelRoot, 'end' ), parseModel( item1, modelDoc.schema ) )
-								.insert( ModelPosition.createAt( modelRoot, 'end' ), parseModel( item2, modelDoc.schema ) );
+							const batch = modelDoc.batch();
+
+							batch.append( parseModel( item1, modelDoc.schema ), modelRoot );
+							batch.append( parseModel( item2, modelDoc.schema ), modelRoot );
 						} );
 					}
 				);
@@ -2660,7 +2661,7 @@ describe( 'ListEngine', () => {
 			setModelData( modelDoc, input );
 
 			modelDoc.enqueueChanges( () => {
-				modelDoc.batch( 'transparent' ).insert( modelDoc.selection.getFirstPosition(), parseModel( inserted, modelDoc.schema ) );
+				modelDoc.batch( 'transparent' ).insert( parseModel( inserted, modelDoc.schema ), modelDoc.selection.getFirstPosition() );
 			} );
 
 			expect( getModelData( modelDoc, { withoutSelection: true } ) ).to.equal( output );
@@ -2672,7 +2673,7 @@ describe( 'ListEngine', () => {
 					setModelData( modelDoc, input );
 
 					modelDoc.enqueueChanges( () => {
-						modelDoc.batch().insert( modelDoc.selection.getFirstPosition(), parseModel( inserted, modelDoc.schema ) );
+						modelDoc.batch().insert( parseModel( inserted, modelDoc.schema ), modelDoc.selection.getFirstPosition() );
 					} );
 
 					expect( getModelData( modelDoc, { withoutSelection: true } ) ).to.equal( output );
@@ -2806,9 +2807,10 @@ describe( 'ListEngine', () => {
 				const item2 = '<listItem indent="1" type="bulleted">d</listItem>';
 
 				modelDoc.enqueueChanges( () => {
-					modelDoc.batch()
-						.insert( ModelPosition.createAt( modelRoot, 'end' ), parseModel( item1, modelDoc.schema ) )
-						.insert( ModelPosition.createAt( modelRoot, 'end' ), parseModel( item2, modelDoc.schema ) );
+					const batch = modelDoc.batch();
+
+					batch.append( parseModel( item1, modelDoc.schema ), modelRoot );
+					batch.append( parseModel( item2, modelDoc.schema ), modelRoot );
 				} );
 
 				expect( getModelData( modelDoc, { withoutSelection: true } ) ).to.equal( output );
@@ -3508,7 +3510,7 @@ describe( 'ListEngine', () => {
 
 		const actionCallback = () => {
 			modelDoc.enqueueChanges( () => {
-				modelDoc.batch().insert( modelDoc.selection.getFirstPosition(), parseModel( item, modelDoc.schema ) );
+				modelDoc.batch().insert( parseModel( item, modelDoc.schema ), modelDoc.selection.getFirstPosition() );
 			} );
 		};
 
@@ -3543,10 +3545,11 @@ describe( 'ListEngine', () => {
 			const element = modelDoc.selection.getFirstPosition().nodeAfter;
 
 			modelDoc.enqueueChanges( () => {
-				modelDoc.batch()
-					.rename( element, 'paragraph' )
-					.removeAttribute( element, 'type' )
-					.removeAttribute( element, 'indent' );
+				const batch = modelDoc.batch();
+
+				batch.rename( element, 'paragraph' );
+				batch.removeAttribute( element, 'type' );
+				batch.removeAttribute( element, 'indent' );
 			} );
 		};
 
@@ -3558,10 +3561,11 @@ describe( 'ListEngine', () => {
 			const element = modelDoc.selection.getFirstPosition().nodeAfter;
 
 			modelDoc.enqueueChanges( () => {
-				modelDoc.batch()
-					.setAttribute( element, 'type', 'bulleted' )
-					.setAttribute( element, 'indent', newIndent )
-					.rename( element, 'listItem' );
+				const batch = modelDoc.batch();
+
+				batch.setAttribute( element, 'type', 'bulleted' );
+				batch.setAttribute( element, 'indent', newIndent );
+				batch.rename( element, 'listItem' );
 			} );
 		};