8
0
Просмотр исходного кода

Merge branch t/engine/1186

Internal: Update API usage after merge t/1186 on engine.
Piotr Jasiun 8 лет назад
Родитель
Сommit
a0f4aab538

+ 2 - 4
packages/ckeditor5-autoformat/src/autoformat.js

@@ -117,10 +117,8 @@ export default class Autoformat extends Plugin {
 				const pattern = new RegExp( `^(#{${ level }})\\s$` );
 				const pattern = new RegExp( `^(#{${ level }})\\s$` );
 
 
 				// eslint-disable-next-line no-new
 				// eslint-disable-next-line no-new
-				new BlockAutoformatEngine( this.editor, pattern, context => {
-					const { batch } = context;
-
-					this.editor.execute( commandName, { batch } );
+				new BlockAutoformatEngine( this.editor, pattern, () => {
+					this.editor.execute( commandName );
 				} );
 				} );
 			} );
 			} );
 	}
 	}

+ 9 - 16
packages/ckeditor5-autoformat/src/blockautoformatengine.js

@@ -36,11 +36,10 @@ export default class BlockAutoformatEngine {
 	 * To convert a paragraph to heading 1 when `- ` is typed, using just the callback:
 	 * To convert a paragraph to heading 1 when `- ` is typed, using just the callback:
 	 *
 	 *
 	 *		new BlockAutoformatEngine( editor, /^\- $/, ( context ) => {
 	 *		new BlockAutoformatEngine( editor, /^\- $/, ( context ) => {
-	 *			const { batch, match } = context;
+	 *			const { match } = context;
 	 *			const headingLevel = match[ 1 ].length;
 	 *			const headingLevel = match[ 1 ].length;
 	 *
 	 *
 	 *			editor.execute( 'heading', {
 	 *			editor.execute( 'heading', {
-	 *				batch,
 	 *				formatId: `heading${ headingLevel }`
 	 *				formatId: `heading${ headingLevel }`
 	 *			} );
 	 *			} );
 	 * 		} );
 	 * 		} );
@@ -48,8 +47,7 @@ export default class BlockAutoformatEngine {
 	 * @param {module:core/editor/editor~Editor} editor The editor instance.
 	 * @param {module:core/editor/editor~Editor} editor The editor instance.
 	 * @param {RegExp} pattern The regular expression to execute on just inserted text.
 	 * @param {RegExp} pattern The regular expression to execute on just inserted text.
 	 * @param {Function|String} callbackOrCommand The callback to execute or the command to run when the text is matched.
 	 * @param {Function|String} callbackOrCommand The callback to execute or the command to run when the text is matched.
-	 * In case of providing the callback, it receives the following parameters:
-	 * * {module:engine/model/batch~Batch} batch Newly created batch for autoformat changes.
+	 * In case of providing the callback, it receives the following parameter:
 	 * * {Object} match RegExp.exec() result of matching the pattern to inserted text.
 	 * * {Object} match RegExp.exec() result of matching the pattern to inserted text.
 	 */
 	 */
 	constructor( editor, pattern, callbackOrCommand ) {
 	constructor( editor, pattern, callbackOrCommand ) {
@@ -61,15 +59,12 @@ export default class BlockAutoformatEngine {
 			// We assume that the actual command name was provided.
 			// We assume that the actual command name was provided.
 			const command = callbackOrCommand;
 			const command = callbackOrCommand;
 
 
-			callback = context => {
-				const { batch } = context;
-
-				// Create new batch for removal and command execution.
-				editor.execute( command, { batch } );
+			callback = () => {
+				editor.execute( command );
 			};
 			};
 		}
 		}
 
 
-		editor.document.on( 'change', ( event, type, changes, batch ) => {
+		editor.model.document.on( 'change', ( event, type, changes, batch ) => {
 			if ( batch.type == 'transparent' ) {
 			if ( batch.type == 'transparent' ) {
 				return;
 				return;
 			}
 			}
@@ -100,17 +95,15 @@ export default class BlockAutoformatEngine {
 				return;
 				return;
 			}
 			}
 
 
-			editor.document.enqueueChanges( () => {
-				// Create new batch to separate typing batch from the Autoformat changes.
-				const fixBatch = editor.document.batch();
-
+			// Use enqueueChange to create new batch to separate typing batch from the autoformat changes.
+			editor.model.enqueueChange( writer => {
 				// Matched range.
 				// Matched range.
 				const range = Range.createFromParentsAndOffsets( textNode.parent, 0, textNode.parent, match[ 0 ].length );
 				const range = Range.createFromParentsAndOffsets( textNode.parent, 0, textNode.parent, match[ 0 ].length );
 
 
 				// Remove matched text.
 				// Remove matched text.
-				fixBatch.remove( range );
+				writer.remove( range );
 
 
-				callback( { fixBatch, match } );
+				callback( { match } );
 			} );
 			} );
 		} );
 		} );
 	}
 	}

+ 11 - 13
packages/ckeditor5-autoformat/src/inlineautoformatengine.js

@@ -60,9 +60,9 @@ export default class InlineAutoformatEngine {
 	 *		new InlineAutoformatEngine( editor, /(\*\*)([^\*]+?)(\*\*)$/g, 'bold' );
 	 *		new InlineAutoformatEngine( editor, /(\*\*)([^\*]+?)(\*\*)$/g, 'bold' );
 	 *
 	 *
 	 *		// Use formatting callback:
 	 *		// Use formatting callback:
-	 *		new InlineAutoformatEngine( editor, /(\*\*)([^\*]+?)(\*\*)$/g, ( batch, validRanges ) => {
+	 *		new InlineAutoformatEngine( editor, /(\*\*)([^\*]+?)(\*\*)$/g, ( writer, validRanges ) => {
 	 *			for ( let range of validRanges ) {
 	 *			for ( let range of validRanges ) {
-	 *				batch.setAttribute( command, true, range );
+	 *				writer.setAttribute( command, true, range );
 	 *			}
 	 *			}
 	 *		} );
 	 *		} );
 	 */
 	 */
@@ -130,13 +130,13 @@ export default class InlineAutoformatEngine {
 		} );
 		} );
 
 
 		// A format callback run on matched text.
 		// A format callback run on matched text.
-		formatCallback = formatCallback || ( ( batch, validRanges ) => {
+		formatCallback = formatCallback || ( ( writer, validRanges ) => {
 			for ( const range of validRanges ) {
 			for ( const range of validRanges ) {
-				batch.setAttribute( command, true, range );
+				writer.setAttribute( command, true, range );
 			}
 			}
 		} );
 		} );
 
 
-		editor.document.on( 'change', ( evt, type, changes, batch ) => {
+		editor.model.document.on( 'change', ( evt, type, changes, batch ) => {
 			if ( batch.type == 'transparent' ) {
 			if ( batch.type == 'transparent' ) {
 				return;
 				return;
 			}
 			}
@@ -145,7 +145,7 @@ export default class InlineAutoformatEngine {
 				return;
 				return;
 			}
 			}
 
 
-			const selection = editor.document.selection;
+			const selection = editor.model.document.selection;
 
 
 			if ( !selection.isCollapsed || !selection.focus || !selection.focus.parent ) {
 			if ( !selection.isCollapsed || !selection.focus || !selection.focus.parent ) {
 				return;
 				return;
@@ -186,21 +186,19 @@ export default class InlineAutoformatEngine {
 				return;
 				return;
 			}
 			}
 
 
-			editor.document.enqueueChanges( () => {
-				// Create new batch to separate typing batch from the Autoformat changes.
-				const fixBatch = editor.document.batch();
-
-				const validRanges = editor.document.schema.getValidRanges( rangesToFormat, command );
+			// Use enqueueChange to create new batch to separate typing batch from the autoformat changes.
+			editor.model.enqueueChange( writer => {
+				const validRanges = editor.model.schema.getValidRanges( rangesToFormat, command );
 
 
 				// Apply format.
 				// Apply format.
-				formatCallback( fixBatch, validRanges );
+				formatCallback( writer, validRanges );
 
 
 				// Detach ranges used to apply Autoformat. Prevents memory leaks. #39
 				// Detach ranges used to apply Autoformat. Prevents memory leaks. #39
 				rangesToFormat.forEach( range => range.detach() );
 				rangesToFormat.forEach( range => range.detach() );
 
 
 				// Remove delimiters.
 				// Remove delimiters.
 				for ( const range of rangesToRemove ) {
 				for ( const range of rangesToRemove ) {
-					fixBatch.remove( range );
+					writer.remove( range );
 
 
 					// Prevents memory leaks.
 					// Prevents memory leaks.
 					// https://github.com/ckeditor/ckeditor5-autoformat/issues/39
 					// https://github.com/ckeditor/ckeditor5-autoformat/issues/39

+ 131 - 130
packages/ckeditor5-autoformat/tests/autoformat.js

@@ -24,7 +24,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'Autoformat', () => {
 describe( 'Autoformat', () => {
-	let editor, doc, batch;
+	let editor, model, doc;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -43,8 +43,8 @@ describe( 'Autoformat', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				doc = editor.document;
-				batch = doc.batch();
+				model = editor.model;
+				doc = model.document;
 			} );
 			} );
 	} );
 	} );
 
 
@@ -54,97 +54,97 @@ describe( 'Autoformat', () => {
 
 
 	describe( 'Bulleted list', () => {
 	describe( 'Bulleted list', () => {
 		it( 'should replace asterisk with bulleted list item', () => {
 		it( 'should replace asterisk with bulleted list item', () => {
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should replace minus character with bulleted list item', () => {
 		it( 'should replace minus character with bulleted list item', () => {
-			setData( doc, '<paragraph>-[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>-[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should not replace minus character when inside bulleted list item', () => {
 		it( 'should not replace minus character when inside bulleted list item', () => {
-			setData( doc, '<listItem indent="0" type="bulleted">-[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="bulleted">-[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'Numbered list', () => {
 	describe( 'Numbered list', () => {
 		it( 'should replace digit with numbered list item using the dot format', () => {
 		it( 'should replace digit with numbered list item using the dot format', () => {
-			setData( doc, '<paragraph>1.[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1.[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should replace digit with numbered list item using the parenthesis format', () => {
 		it( 'should replace digit with numbered list item using the parenthesis format', () => {
-			setData( doc, '<paragraph>1)[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1)[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should not replace digit character when there is no . or ) in the format', () => {
 		it( 'should not replace digit character when there is no . or ) in the format', () => {
-			setData( doc, '<paragraph>1[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>1 []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>1 []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace digit character when inside numbered list item', () => {
 		it( 'should not replace digit character when inside numbered list item', () => {
-			setData( doc, '<listItem indent="0" type="numbered">1.[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="numbered">1.[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'Heading', () => {
 	describe( 'Heading', () => {
 		it( 'should replace hash character with heading', () => {
 		it( 'should replace hash character with heading', () => {
-			setData( doc, '<paragraph>#[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>#[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading1>[]</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
 		} );
 		} );
 
 
 		it( 'should replace two hash characters with heading level 2', () => {
 		it( 'should replace two hash characters with heading level 2', () => {
-			setData( doc, '<paragraph>##[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>##[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading2>[]</heading2>' );
+			expect( getData( model ) ).to.equal( '<heading2>[]</heading2>' );
 		} );
 		} );
 
 
 		it( 'should not replace hash character when inside heading', () => {
 		it( 'should not replace hash character when inside heading', () => {
-			setData( doc, '<heading1>#[]</heading1>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<heading1>#[]</heading1>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading1># []</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1># []</heading1>' );
 		} );
 		} );
 
 
 		it( 'should work with heading1-heading6 commands regardless of the config of the heading feature', () => {
 		it( 'should work with heading1-heading6 commands regardless of the config of the heading feature', () => {
@@ -174,18 +174,19 @@ describe( 'Autoformat', () => {
 					]
 					]
 				} )
 				} )
 				.then( editor => {
 				.then( editor => {
-					const doc = editor.document;
+					const model = editor.model;
+					const doc = model.document;
 
 
-					setData( doc, '<paragraph>#[]</paragraph>' );
-					doc.enqueueChanges( () => {
-						doc.batch().insertText( ' ', doc.selection.getFirstPosition() );
+					setData( model, '<paragraph>#[]</paragraph>' );
+					model.change( writer => {
+						writer.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 					} );
 
 
 					expect( spy1.calledOnce ).to.be.true;
 					expect( spy1.calledOnce ).to.be.true;
 
 
-					setData( doc, '<paragraph>######[]</paragraph>' );
-					doc.enqueueChanges( () => {
-						doc.batch().insertText( ' ', doc.selection.getFirstPosition() );
+					setData( model, '<paragraph>######[]</paragraph>' );
+					model.change( writer => {
+						writer.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 					} );
 
 
 					expect( spy6.calledOnce ).to.be.true;
 					expect( spy6.calledOnce ).to.be.true;
@@ -197,86 +198,86 @@ describe( 'Autoformat', () => {
 
 
 	describe( 'Block quote', () => {
 	describe( 'Block quote', () => {
 		it( 'should replace greater-than character with heading', () => {
 		it( 'should replace greater-than character with heading', () => {
-			setData( doc, '<paragraph>>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
+			expect( getData( model ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
 		} );
 		} );
 
 
 		it( 'should not replace greater-than character when inside heading', () => {
 		it( 'should not replace greater-than character when inside heading', () => {
-			setData( doc, '<heading1>>[]</heading1>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<heading1>>[]</heading1>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading1>> []</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1>> []</heading1>' );
 		} );
 		} );
 
 
 		it( 'should not replace greater-than character when inside numbered list', () => {
 		it( 'should not replace greater-than character when inside numbered list', () => {
-			setData( doc, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
 		} );
 		} );
 
 
 		it( 'should not replace greater-than character when inside buletted list', () => {
 		it( 'should not replace greater-than character when inside buletted list', () => {
-			setData( doc, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'Inline autoformat', () => {
 	describe( 'Inline autoformat', () => {
 		it( 'should replace both "**" with bold', () => {
 		it( 'should replace both "**" with bold', () => {
-			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>**foobar*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should replace both "*" with italic', () => {
 		it( 'should replace both "*" with italic', () => {
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should replace both "`" with code', () => {
 		it( 'should replace both "`" with code', () => {
-			setData( doc, '<paragraph>`foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '`', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>`foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '`', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'nothing should be replaces when typing "*"', () => {
 		it( 'nothing should be replaces when typing "*"', () => {
-			setData( doc, '<paragraph>foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should format inside the text', () => {
 		it( 'should format inside the text', () => {
-			setData( doc, '<paragraph>foo **bar*[] baz</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>foo **bar*[] baz</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -288,90 +289,90 @@ describe( 'Autoformat', () => {
 				} )
 				} )
 				.then( newEditor => {
 				.then( newEditor => {
 					editor = newEditor;
 					editor = newEditor;
-					doc = editor.document;
-					batch = doc.batch();
+					model = editor.model;
+					doc = model.document;
 				} );
 				} );
 		} );
 		} );
 
 
 		it( 'should not replace asterisk with bulleted list item', () => {
 		it( 'should not replace asterisk with bulleted list item', () => {
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>* []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>* []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace minus character with bulleted list item', () => {
 		it( 'should not replace minus character with bulleted list item', () => {
-			setData( doc, '<paragraph>-[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>-[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>- []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>- []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace digit with numbered list item', () => {
 		it( 'should not replace digit with numbered list item', () => {
-			setData( doc, '<paragraph>1.[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1.[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>1. []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>1. []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace hash character with heading', () => {
 		it( 'should not replace hash character with heading', () => {
-			setData( doc, '<paragraph>#[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>#[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph># []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph># []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace two hash characters with heading level 2', () => {
 		it( 'should not replace two hash characters with heading level 2', () => {
-			setData( doc, '<paragraph>##[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>##[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace both "**" with bold', () => {
 		it( 'should not replace both "**" with bold', () => {
-			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>**foobar*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace both "*" with italic', () => {
 		it( 'should not replace both "*" with italic', () => {
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace both "`" with code', () => {
 		it( 'should not replace both "`" with code', () => {
-			setData( doc, '<paragraph>`foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '`', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>`foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '`', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace ">" with block quote', () => {
 		it( 'should not replace ">" with block quote', () => {
-			setData( doc, '<paragraph>>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>> []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>> []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should use only configured headings', () => {
 		it( 'should use only configured headings', () => {
@@ -386,15 +387,15 @@ describe( 'Autoformat', () => {
 					}
 					}
 				} )
 				} )
 				.then( editor => {
 				.then( editor => {
-					doc = editor.document;
-					batch = doc.batch();
+					model = editor.model;
+					doc = model.document;
 
 
-					setData( doc, '<paragraph>##[]</paragraph>' );
-					doc.enqueueChanges( () => {
-						batch.insertText( ' ', doc.selection.getFirstPosition() );
+					setData( model, '<paragraph>##[]</paragraph>' );
+					model.change( writer => {
+						writer.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 					} );
 
 
-					expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
+					expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );
 				} );
 				} );
 		} );
 		} );
 	} );
 	} );

+ 25 - 25
packages/ckeditor5-autoformat/tests/blockautoformatengine.js

@@ -14,7 +14,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'BlockAutoformatEngine', () => {
 describe( 'BlockAutoformatEngine', () => {
-	let editor, doc, batch;
+	let editor, model, doc;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -23,8 +23,8 @@ describe( 'BlockAutoformatEngine', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				doc = editor.document;
-				batch = doc.batch();
+				model = editor.model;
+				doc = model.document;
 			} );
 			} );
 	} );
 	} );
 
 
@@ -34,9 +34,9 @@ describe( 'BlockAutoformatEngine', () => {
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
@@ -47,9 +47,9 @@ describe( 'BlockAutoformatEngine', () => {
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -60,13 +60,13 @@ describe( 'BlockAutoformatEngine', () => {
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
-			expect( getData( doc ) ).to.equal( '<paragraph>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -75,9 +75,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
@@ -87,9 +87,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -99,9 +99,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.remove( doc.selection.getFirstRange() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.remove( doc.selection.getFirstRange() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -111,9 +111,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );

+ 36 - 36
packages/ckeditor5-autoformat/tests/inlineautoformatengine.js

@@ -13,7 +13,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'InlineAutoformatEngine', () => {
 describe( 'InlineAutoformatEngine', () => {
-	let editor, doc, batch;
+	let editor, model, doc;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -22,9 +22,9 @@ describe( 'InlineAutoformatEngine', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				doc = editor.document;
-				batch = doc.batch();
-				doc.schema.allow( { name: '$inline', attributes: [ 'testAttribute' ] } );
+				model = editor.model;
+				doc = model.document;
+				model.schema.allow( { name: '$inline', attributes: [ 'testAttribute' ] } );
 			} );
 			} );
 	} );
 	} );
 
 
@@ -32,45 +32,45 @@ describe( 'InlineAutoformatEngine', () => {
 		it( 'should stop early if there are less than 3 capture groups', () => {
 		it( 'should stop early if there are less than 3 capture groups', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should apply an attribute when the pattern is matched', () => {
 		it( 'should apply an attribute when the pattern is matched', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text testAttribute="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text testAttribute="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not apply an attribute when changes are in transparent batch', () => {
 		it( 'should not apply an attribute when changes are in transparent batch', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should stop early if selection is not collapsed', () => {
 		it( 'should stop early if selection is not collapsed', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foob[ar]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foob[ar]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foob*[ar]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foob*[ar]</paragraph>' );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -79,9 +79,9 @@ describe( 'InlineAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, spy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -96,9 +96,9 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( formatSpy );
 			sinon.assert.notCalled( formatSpy );
@@ -113,9 +113,9 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( formatSpy );
 			sinon.assert.notCalled( formatSpy );
@@ -130,9 +130,9 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( formatSpy );
 			sinon.assert.notCalled( formatSpy );
@@ -141,16 +141,16 @@ describe( 'InlineAutoformatEngine', () => {
 		it( 'should detach removed ranges', () => {
 		it( 'should detach removed ranges', () => {
 			const detachSpies = [];
 			const detachSpies = [];
 			const callback = fixBatch => testUtils.sinon.stub( fixBatch, 'remove' ).callsFake( saveDetachSpy );
 			const callback = fixBatch => testUtils.sinon.stub( fixBatch, 'remove' ).callsFake( saveDetachSpy );
-			testUtils.sinon.stub( editor.document.schema, 'getValidRanges' )
+			testUtils.sinon.stub( editor.model.schema, 'getValidRanges' )
 				.callThrough()
 				.callThrough()
 				.callsFake( ranges => ranges.map( saveDetachSpy ) );
 				.callsFake( ranges => ranges.map( saveDetachSpy ) );
 
 
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, callback ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, callback ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
 
 
-			doc.enqueueChanges( () => {
-				doc.batch().insertText( '*', doc.selection.getFirstPosition() );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			// There should be two removed ranges and one range used to apply autoformat.
 			// There should be two removed ranges and one range used to apply autoformat.