8
0
Quellcode durchsuchen

Aligned code to with new Batch#setAttributes API.

Oskar Wróbel vor 8 Jahren
Ursprung
Commit
95c6932b2f

+ 4 - 4
packages/ckeditor5-list/src/converters.js

@@ -612,8 +612,8 @@ export function modelChangePostFixer( document ) {
 
 			// Element name is changed from list to something else. Remove useless attributes.
 			document.enqueueChanges( () => {
-				batch.removeAttribute( element, 'indent' );
-				batch.removeAttribute( element, 'type' );
+				batch.removeAttribute( 'indent', element );
+				batch.removeAttribute( 'type', element );
 			} );
 
 			const changePos = ModelPosition.createAfter( changes.element );
@@ -667,7 +667,7 @@ function _fixItemsIndent( changePosition, document, batch ) {
 			if ( items.length > 0 ) {
 				// Since we are outdenting list items, it is safer to start from the last one (it will maintain correct model state).
 				for ( const item of items.reverse() ) {
-					batch.setAttribute( item.item, 'indent', item.indent );
+					batch.setAttribute( 'indent', item.indent, item.item );
 				}
 			}
 		} );
@@ -701,7 +701,7 @@ function _fixItemsType( changePosition, fixPrevious, document, batch ) {
 
 		while ( item && item.is( 'listItem' ) && item.getAttribute( 'indent' ) >= refIndent ) {
 			if ( item.getAttribute( 'type' ) != refType && item.getAttribute( 'indent' ) == refIndent ) {
-				batch.setAttribute( item, 'type', refType );
+				batch.setAttribute( 'type', refType, item );
 			}
 
 			item = item[ fixPrevious ? 'previousSibling' : 'nextSibling' ];

+ 3 - 3
packages/ckeditor5-list/src/indentcommand.js

@@ -87,7 +87,7 @@ export default class IndentCommand extends Command {
 				}
 				// If indent is >= 0, change the attribute value.
 				else {
-					batch.setAttribute( item, 'indent', indent );
+					batch.setAttribute( 'indent', indent, item );
 				}
 			}
 
@@ -155,7 +155,7 @@ function _fixType( item, batch ) {
 
 	// If found, fix type.
 	if ( prev ) {
-		batch.setAttribute( item, 'type', prev.getAttribute( 'type' ) );
+		batch.setAttribute( 'type', prev.getAttribute( 'type' ), item );
 
 		return;
 	}
@@ -165,7 +165,7 @@ function _fixType( item, batch ) {
 
 	// If found, fix type.
 	if ( next ) {
-		batch.setAttribute( item, 'type', next.getAttribute( 'type' ) );
+		batch.setAttribute( 'type', next.getAttribute( 'type' ), item );
 	}
 }
 

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

@@ -154,7 +154,7 @@ export default class ListCommand extends Command {
 				changes = changes.reverse();
 
 				for ( const item of changes ) {
-					batch.setAttribute( item.element, 'indent', item.indent );
+					batch.setAttribute( 'indent', item.indent, item.element );
 				}
 			}
 
@@ -208,13 +208,12 @@ 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 );
-					batch.setAttribute( element, 'indent', 0 );
+					batch.setAttributes( { type: this.type, indent: 0 }, element );
 					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.
-					batch.setAttribute( element, 'type', this.type );
+					batch.setAttribute( 'type', this.type, element );
 				}
 			}
 		} );

+ 8 - 9
packages/ckeditor5-list/tests/listengine.js

@@ -3353,7 +3353,7 @@ describe( 'ListEngine', () => {
 
 			setModelData( modelDoc, '<listItem indent="0" type="bulleted"></listItem>' );
 
-			modelDoc.batch().setAttribute( modelRoot.getChild( 0 ), 'type', 'numbered' );
+			modelDoc.batch().setAttribute( 'type', 'numbered', modelRoot.getChild( 0 ) );
 
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<ul><li></li></ul>' );
 		} );
@@ -3365,7 +3365,7 @@ describe( 'ListEngine', () => {
 
 			setModelData( modelDoc, '<listItem indent="0" type="bulleted">a</listItem><listItem indent="0" type="bulleted">b</listItem>' );
 
-			modelDoc.batch().setAttribute( modelRoot.getChild( 1 ), 'indent', 1 );
+			modelDoc.batch().setAttribute( 'indent', 1, modelRoot.getChild( 1 ) );
 
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<ul><li>a</li><li>b</li></ul>' );
 		} );
@@ -3411,7 +3411,7 @@ describe( 'ListEngine', () => {
 				.to.equal( '<ul><li>Foo<span></span></li><li>Bar</li></ul>' );
 
 			// Change indent of the second list item.
-			modelDoc.batch().setAttribute( modelRoot.getChild( 1 ), 'indent', 1 );
+			modelDoc.batch().setAttribute( 'indent', 1, modelRoot.getChild( 1 ) );
 
 			// Check if the new <ul> was added at correct position.
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
@@ -3536,7 +3536,7 @@ describe( 'ListEngine', () => {
 			const newType = element.getAttribute( 'type' ) == 'numbered' ? 'bulleted' : 'numbered';
 
 			modelDoc.enqueueChanges( () => {
-				modelDoc.batch().setAttribute( modelDoc.selection.getFirstRange(), 'type', newType );
+				modelDoc.batch().setAttribute( 'type', newType, modelDoc.selection.getFirstRange() );
 			} );
 		};
 
@@ -3551,8 +3551,8 @@ describe( 'ListEngine', () => {
 				const batch = modelDoc.batch();
 
 				batch.rename( element, 'paragraph' );
-				batch.removeAttribute( element, 'type' );
-				batch.removeAttribute( element, 'indent' );
+				batch.removeAttribute( 'type', element );
+				batch.removeAttribute( 'indent', element );
 			} );
 		};
 
@@ -3566,8 +3566,7 @@ describe( 'ListEngine', () => {
 			modelDoc.enqueueChanges( () => {
 				const batch = modelDoc.batch();
 
-				batch.setAttribute( element, 'type', 'bulleted' );
-				batch.setAttribute( element, 'indent', newIndent );
+				batch.setAttributes( { type: 'bulleted', indent: newIndent }, element );
 				batch.rename( element, 'listItem' );
 			} );
 		};
@@ -3578,7 +3577,7 @@ describe( 'ListEngine', () => {
 	function testChangeIndent( testName, newIndent, input, output ) {
 		const actionCallback = () => {
 			modelDoc.enqueueChanges( () => {
-				modelDoc.batch().setAttribute( modelDoc.selection.getFirstRange(), 'indent', newIndent );
+				modelDoc.batch().setAttribute( 'indent', newIndent, modelDoc.selection.getFirstRange() );
 			} );
 		};