8
0
فهرست منبع

Merge branch t/engine/1186

Internal: Update API usage after merge t/1186 on engine.
Piotr Jasiun 8 سال پیش
والد
کامیت
3798130193

+ 3 - 2
packages/ckeditor5-typing/src/changebuffer.js

@@ -8,6 +8,7 @@
  */
 
 import count from '@ckeditor/ckeditor5-utils/src/count';
+import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
 
 /**
  * Change buffer allows to group atomic changes (like characters that have been typed) into
@@ -31,7 +32,7 @@ export default class ChangeBuffer {
 	/**
 	 * Creates a new instance of the change buffer.
 	 *
-	 * @param {module:engine/model/document~Document} document
+	 * @param {module:engine/model/document~Document} doc
 	 * @param {Number} [limit=20] The maximum number of atomic changes which can be contained in one batch.
 	 */
 	constructor( doc, limit = 20 ) {
@@ -112,7 +113,7 @@ export default class ChangeBuffer {
 	 */
 	get batch() {
 		if ( !this._batch ) {
-			this._batch = this.document.batch();
+			this._batch = new Batch();
 		}
 
 		return this._batch;

+ 18 - 15
packages/ckeditor5-typing/src/deletecommand.js

@@ -47,7 +47,7 @@ export default class DeleteCommand extends Command {
 		 * @private
 		 * @member {typing.ChangeBuffer} #buffer
 		 */
-		this._buffer = new ChangeBuffer( editor.document, editor.config.get( 'typing.undoStep' ) );
+		this._buffer = new ChangeBuffer( editor.model.document, editor.config.get( 'typing.undoStep' ) );
 	}
 
 	/**
@@ -61,10 +61,11 @@ export default class DeleteCommand extends Command {
 	 * See the {@link module:engine/view/document~Document#event:delete} event data.
 	 */
 	execute( options = {} ) {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = model.document;
 		const dataController = this.editor.data;
 
-		doc.enqueueChanges( () => {
+		model.enqueueChange( this._buffer.batch, writer => {
 			this._buffer.lock();
 
 			const selection = Selection.createFromSelection( doc.selection );
@@ -83,7 +84,7 @@ export default class DeleteCommand extends Command {
 
 			// Check if deleting in an empty editor. See #61.
 			if ( this._shouldEntireContentBeReplacedWithParagraph( options.sequence || 1 ) ) {
-				this._replaceEntireContentWithParagraph();
+				this._replaceEntireContentWithParagraph( writer );
 
 				return;
 			}
@@ -101,7 +102,7 @@ export default class DeleteCommand extends Command {
 				);
 			} );
 
-			dataController.deleteContent( selection, this._buffer.batch, { doNotResetEntireContent } );
+			dataController.deleteContent( selection, { doNotResetEntireContent } );
 			this._buffer.input( changeCount );
 
 			doc.selection.setRanges( selection.getRanges(), selection.isBackward );
@@ -134,9 +135,10 @@ export default class DeleteCommand extends Command {
 			return false;
 		}
 
-		const document = this.editor.document;
-		const selection = document.selection;
-		const limitElement = document.schema.getLimitElement( selection );
+		const model = this.editor.model;
+		const doc = model.document;
+		const selection = doc.selection;
+		const limitElement = model.schema.getLimitElement( selection );
 
 		// If a collapsed selection contains the whole content it means that the content is empty
 		// (from the user perspective).
@@ -146,7 +148,7 @@ export default class DeleteCommand extends Command {
 			return false;
 		}
 
-		if ( !document.schema.check( { name: 'paragraph', inside: limitElement.name } ) ) {
+		if ( !model.schema.check( { name: 'paragraph', inside: limitElement.name } ) ) {
 			return false;
 		}
 
@@ -167,14 +169,15 @@ export default class DeleteCommand extends Command {
 	 *
 	 * @private
 	 */
-	_replaceEntireContentWithParagraph() {
-		const document = this.editor.document;
-		const selection = document.selection;
-		const limitElement = document.schema.getLimitElement( selection );
+	_replaceEntireContentWithParagraph( writer ) {
+		const model = this.editor.model;
+		const doc = model.document;
+		const selection = doc.selection;
+		const limitElement = model.schema.getLimitElement( selection );
 		const paragraph = new Element( 'paragraph' );
 
-		this._buffer.batch.remove( Range.createIn( limitElement ) );
-		this._buffer.batch.insert( paragraph, limitElement );
+		writer.remove( Range.createIn( limitElement ) );
+		writer.insert( paragraph, limitElement );
 
 		selection.setCollapsedAt( paragraph );
 	}

+ 5 - 5
packages/ckeditor5-typing/src/input.js

@@ -68,7 +68,8 @@ export default class Input extends Plugin {
 	 * @param {module:typing/inputcommand~InputCommand} inputCommand
 	 */
 	_handleKeydown( evtData, inputCommand ) {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = model.document;
 		const buffer = inputCommand.buffer;
 
 		// By relying on the state of the input command we allow disabling the entire input easily
@@ -86,8 +87,8 @@ export default class Input extends Plugin {
 
 		buffer.lock();
 
-		doc.enqueueChanges( () => {
-			this.editor.data.deleteContent( doc.selection, buffer.batch );
+		model.enqueueChange( buffer.batch, () => {
+			this.editor.data.deleteContent( doc.selection );
 		} );
 
 		buffer.unlock();
@@ -194,8 +195,7 @@ class MutationHandler {
 		// This wouldn't be needed if DomConverter would allow to create fresh view without checking any mappings.
 		const freshDomConverter = new DomConverter();
 		const modelFromCurrentDom = this.editor.data.toModel(
-			freshDomConverter.domToView( domMutationCommonAncestor ),
-			this.editor.commands.get( 'input' ).buffer.batch
+			freshDomConverter.domToView( domMutationCommonAncestor )
 		).getChild( 0 );
 
 		// Current model.

+ 8 - 7
packages/ckeditor5-typing/src/inputcommand.js

@@ -33,7 +33,7 @@ export default class InputCommand extends Command {
 		 * @private
 		 * @member {module:typing/changebuffer~ChangeBuffer} #_buffer
 		 */
-		this._buffer = new ChangeBuffer( editor.document, undoStepSize );
+		this._buffer = new ChangeBuffer( editor.model.document, undoStepSize );
 	}
 
 	/**
@@ -69,30 +69,31 @@ export default class InputCommand extends Command {
 	 * the inserted text.
 	 */
 	execute( options = {} ) {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = model.document;
 		const text = options.text || '';
 		const textInsertions = text.length;
 		const range = options.range || doc.selection.getFirstRange();
 		const resultRange = options.resultRange;
 
-		doc.enqueueChanges( () => {
+		model.enqueueChange( this._buffer.batch, writer => {
 			const isCollapsedRange = range.isCollapsed;
 
 			this._buffer.lock();
 
 			if ( !isCollapsedRange ) {
-				this._buffer.batch.remove( range );
+				writer.remove( range );
 			}
 
 			if ( text ) {
-				this._buffer.batch.insertText( text, doc.selection.getAttributes(), range.start );
+				writer.insertText( text, doc.selection.getAttributes(), range.start );
 			}
 
 			if ( resultRange ) {
-				this.editor.data.model.selection.setRanges( [ resultRange ] );
+				doc.selection.setRanges( [ resultRange ] );
 			} else if ( isCollapsedRange ) {
 				// If range was collapsed just shift the selection by the number of inserted characters.
-				this.editor.data.model.selection.setCollapsedAt( range.start.getShiftedBy( textInsertions ) );
+				doc.selection.setCollapsedAt( range.start.getShiftedBy( textInsertions ) );
 			}
 
 			this._buffer.unlock();

+ 18 - 18
packages/ckeditor5-typing/tests/bogusbr-integration.js

@@ -44,12 +44,12 @@ describe( 'Typing – bogus BR integration', () => {
 		// a little different in every browser (as native mutations may be different in different browsers).
 
 		it( 'space is inserted on the end of the line (paragraph)', done => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				editor.editing.view.getDomRoot().focus();
-				setData( editor.document, '<paragraph>Foo[]</paragraph>' );
+				setData( editor.model, '<paragraph>Foo[]</paragraph>' );
 			} );
 
-			editor.document.once( 'changesDone', () => {
+			editor.model.document.once( 'changesDone', () => {
 				expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
 				done();
 			}, { priority: 'low' } );
@@ -58,12 +58,12 @@ describe( 'Typing – bogus BR integration', () => {
 		} );
 
 		it( 'space is inserted on the end of the line (empty paragraph)', done => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				editor.editing.view.getDomRoot().focus();
-				setData( editor.document, '<paragraph>[]</paragraph>' );
+				setData( editor.model, '<paragraph>[]</paragraph>' );
 			} );
 
-			editor.document.once( 'changesDone', () => {
+			editor.model.document.once( 'changesDone', () => {
 				expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
 				done();
 			}, { priority: 'low' } );
@@ -72,12 +72,12 @@ describe( 'Typing – bogus BR integration', () => {
 		} );
 
 		it( 'space is inserted on the end of the line (bold)', done => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				editor.editing.view.getDomRoot().focus();
-				setData( editor.document, '<paragraph><$text bold="true">Foo[]</$text></paragraph>' );
+				setData( editor.model, '<paragraph><$text bold="true">Foo[]</$text></paragraph>' );
 			} );
 
-			editor.document.once( 'changesDone', () => {
+			editor.model.document.once( 'changesDone', () => {
 				expect( editor.getData() ).to.equal( '<p><strong>Foo&nbsp;</strong></p>' );
 				done();
 			}, { priority: 'low' } );
@@ -90,12 +90,12 @@ describe( 'Typing – bogus BR integration', () => {
 		// This tests use fixed list of mutation mocks to simulate specific browser behaviours.
 
 		it( 'space is inserted on the end of the paragraph', done => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				editor.editing.view.getDomRoot().focus();
-				setData( editor.document, '<paragraph>Foo[]</paragraph>' );
+				setData( editor.model, '<paragraph>Foo[]</paragraph>' );
 			} );
 
-			editor.document.once( 'changesDone', () => {
+			editor.model.document.once( 'changesDone', () => {
 				expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
 				done();
 			}, { priority: 'low' } );
@@ -116,12 +116,12 @@ describe( 'Typing – bogus BR integration', () => {
 		} );
 
 		it( 'space is inserted on the end of the line paragraph (with bogus br)', done => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				editor.editing.view.getDomRoot().focus();
-				setData( editor.document, '<paragraph>Foo[]</paragraph>' );
+				setData( editor.model, '<paragraph>Foo[]</paragraph>' );
 			} );
 
-			editor.document.once( 'changesDone', () => {
+			editor.model.document.once( 'changesDone', () => {
 				expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
 				done();
 			}, { priority: 'low' } );
@@ -145,12 +145,12 @@ describe( 'Typing – bogus BR integration', () => {
 		} );
 
 		it( 'word is properly corrected on the end of the block element (with bogus br)', done => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				editor.editing.view.getDomRoot().focus();
-				setData( editor.document, '<paragraph>Foo hous[]</paragraph>' );
+				setData( editor.model, '<paragraph>Foo hous[]</paragraph>' );
 			} );
 
-			editor.document.once( 'changesDone', () => {
+			editor.model.document.once( 'changesDone', () => {
 				expect( editor.getData() ).to.equal( '<p>Foo house</p>' );
 				done();
 			}, { priority: 'low' } );

+ 37 - 13
packages/ckeditor5-typing/tests/changebuffer.js

@@ -4,15 +4,16 @@
  */
 
 import ChangeBuffer from '../src/changebuffer';
-import Document from '@ckeditor/ckeditor5-engine/src/model/document';
+import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
 
 describe( 'ChangeBuffer', () => {
 	const CHANGE_LIMIT = 3;
-	let doc, buffer, root;
+	let model, doc, buffer, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 		buffer = new ChangeBuffer( doc, CHANGE_LIMIT );
 	} );
@@ -90,7 +91,9 @@ describe( 'ChangeBuffer', () => {
 			// Ensure that size is reset too.
 			buffer.input( 1 );
 
-			doc.batch().insertText( 'a', root );
+			model.change( writer => {
+				writer.insertText( 'a', root );
+			} );
 
 			expect( buffer.batch ).to.not.equal( batch1 );
 			expect( buffer.size ).to.equal( 0 );
@@ -99,31 +102,48 @@ describe( 'ChangeBuffer', () => {
 		it( 'is not reset when changes are added to the buffer\'s batch', () => {
 			const batch1 = buffer.batch;
 
-			buffer.batch.insert( 'a', root );
+			model.enqueueChange( buffer.batch, writer => {
+				writer.insert( 'a', root );
+			} );
 			expect( buffer.batch ).to.equal( batch1 );
 
-			buffer.batch.insert( 'b', root );
+			model.enqueueChange( buffer.batch, writer => {
+				writer.insert( 'b', root );
+			} );
 			expect( buffer.batch ).to.equal( batch1 );
 		} );
 
 		it( 'is not reset when changes are added to batch which existed previously', () => {
-			const externalBatch = doc.batch();
+			const externalBatch = new Batch();
 
-			externalBatch.insertText( 'a', root );
+			model.change( writer => {
+				writer.insertText( 'a', root );
+			} );
+
+			model.enqueueChange( externalBatch, writer => {
+				writer.insertText( 'a', root );
+			} );
 
 			const bufferBatch = buffer.batch;
 
-			bufferBatch.insertText( 'b', root );
+			model.enqueueChange( bufferBatch, writer => {
+				writer.insertText( 'b', root );
+			} );
+
 			expect( buffer.batch ).to.equal( bufferBatch );
 
-			doc.batch().insertText( 'c', root );
+			model.change( writer => {
+				writer.insertText( 'c', root );
+			} );
 			expect( buffer.batch ).to.not.equal( bufferBatch );
 		} );
 
 		it( 'is not reset when changes are applied in transparent batch', () => {
 			const bufferBatch = buffer.batch;
 
-			doc.batch( 'transparent' ).insert( 'a', root );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insert( 'a', root );
+			} );
 
 			expect( buffer.batch ).to.equal( bufferBatch );
 		} );
@@ -174,7 +194,9 @@ describe( 'ChangeBuffer', () => {
 
 			buffer.lock();
 
-			doc.batch().insertText( 'a', root );
+			model.change( writer => {
+				writer.insertText( 'a', root );
+			} );
 
 			buffer.unlock();
 
@@ -235,7 +257,9 @@ describe( 'ChangeBuffer', () => {
 
 			buffer.destroy();
 
-			doc.batch().insertText( 'a', root );
+			model.change( writer => {
+				writer.insertText( 'a', root );
+			} );
 
 			expect( buffer.batch ).to.equal( batch1 );
 		} );

+ 17 - 17
packages/ckeditor5-typing/tests/deletecommand-integration.js

@@ -9,7 +9,7 @@ import UndoEngine from '@ckeditor/ckeditor5-undo/src/undoengine';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'DeleteCommand integration', () => {
-	let editor, doc;
+	let editor, model;
 
 	beforeEach( () => {
 		return ModelTestEditor
@@ -21,19 +21,19 @@ describe( 'DeleteCommand integration', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				doc = editor.document;
+				model = editor.model;
 
 				const command = new DeleteCommand( editor, 'backward' );
 				editor.commands.add( 'delete', command );
 
 				// Mock paragraph feature.
-				doc.schema.registerItem( 'paragraph', '$block' );
-				doc.schema.allow( { name: 'paragraph', inside: '$block' } );
+				model.schema.registerItem( 'paragraph', '$block' );
+				model.schema.allow( { name: 'paragraph', inside: '$block' } );
 
-				doc.schema.registerItem( 'img', '$inline' );
-				doc.schema.allow( { name: '$text', inside: 'img' } );
+				model.schema.registerItem( 'img', '$inline' );
+				model.schema.allow( { name: '$text', inside: 'img' } );
 
-				doc.schema.objects.add( 'img' );
+				model.schema.objects.add( 'img' );
 			} );
 	} );
 
@@ -42,12 +42,12 @@ describe( 'DeleteCommand integration', () => {
 	} );
 
 	function assertOutput( output ) {
-		expect( getData( doc ) ).to.equal( output );
+		expect( getData( model ) ).to.equal( output );
 	}
 
 	describe( 'with undo', () => {
 		it( 'deletes characters (and group changes in batches) and rollbacks', () => {
-			setData( doc, '<paragraph>123456789[]</paragraph>' );
+			setData( model, '<paragraph>123456789[]</paragraph>' );
 
 			for ( let i = 0; i < 3; ++i ) {
 				editor.execute( 'delete' );
@@ -59,7 +59,7 @@ describe( 'DeleteCommand integration', () => {
 		} );
 
 		it( 'deletes characters (and group changes in batches) and rollbacks - test step', () => {
-			setData( doc, '<paragraph>123456789[]</paragraph>' );
+			setData( model, '<paragraph>123456789[]</paragraph>' );
 
 			for ( let i = 0; i < 6; ++i ) {
 				editor.execute( 'delete' );
@@ -75,7 +75,7 @@ describe( 'DeleteCommand integration', () => {
 		} );
 
 		it( 'deletes elements (and group changes in batches) and rollbacks', () => {
-			setData( doc, '<paragraph><img>1</img><img>2</img><img>3</img><img>4</img><img>5</img><img>6</img>[]</paragraph>' );
+			setData( model, '<paragraph><img>1</img><img>2</img><img>3</img><img>4</img><img>5</img><img>6</img>[]</paragraph>' );
 
 			for ( let i = 0; i < 3; ++i ) {
 				editor.execute( 'delete' );
@@ -87,7 +87,7 @@ describe( 'DeleteCommand integration', () => {
 		} );
 
 		it( 'merges elements (and group changes in batches) and rollbacks', () => {
-			setData( doc, '<paragraph>123456</paragraph><paragraph>[]78</paragraph>' );
+			setData( model, '<paragraph>123456</paragraph><paragraph>[]78</paragraph>' );
 
 			for ( let i = 0; i < 6; ++i ) {
 				editor.execute( 'delete' );
@@ -107,7 +107,7 @@ describe( 'DeleteCommand integration', () => {
 		} );
 
 		it( 'merges elements (and group changes in batches) and rollbacks - non-collapsed selection', () => {
-			setData( doc, '<paragraph>12345[6</paragraph><paragraph>7]8</paragraph>' );
+			setData( model, '<paragraph>12345[6</paragraph><paragraph>7]8</paragraph>' );
 
 			editor.execute( 'delete' );
 			editor.execute( 'delete' );
@@ -125,11 +125,11 @@ describe( 'DeleteCommand integration', () => {
 
 	describe( 'with DataController.deleteContent', () => {
 		beforeEach( () => {
-			doc.schema.registerItem( 'h1', '$block' );
+			model.schema.registerItem( 'h1', '$block' );
 		} );
 
 		it( 'should replace content with paragraph - if whole content is selected', () => {
-			setData( doc, '<h1>[foo</h1><paragraph>bar]</paragraph>' );
+			setData( model, '<h1>[foo</h1><paragraph>bar]</paragraph>' );
 
 			editor.execute( 'delete' );
 
@@ -137,7 +137,7 @@ describe( 'DeleteCommand integration', () => {
 		} );
 
 		it( 'should not replace content with paragraph - if not whole content is selected', () => {
-			setData( doc, '<h1>f[oo</h1><paragraph>bar]</paragraph>' );
+			setData( model, '<h1>f[oo</h1><paragraph>bar]</paragraph>' );
 
 			editor.execute( 'delete' );
 
@@ -145,7 +145,7 @@ describe( 'DeleteCommand integration', () => {
 		} );
 
 		it( 'should not replace content with paragraph - if selection was collapsed', () => {
-			setData( doc, '<h1></h1><paragraph>[]</paragraph>' );
+			setData( model, '<h1></h1><paragraph>[]</paragraph>' );
 
 			editor.execute( 'delete' );
 

+ 51 - 50
packages/ckeditor5-typing/tests/deletecommand.js

@@ -9,7 +9,7 @@ import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 describe( 'DeleteCommand', () => {
-	let editor, doc;
+	let editor, model, doc;
 
 	testUtils.createSinonSandbox();
 
@@ -17,13 +17,14 @@ describe( 'DeleteCommand', () => {
 		return ModelTestEditor.create()
 			.then( newEditor => {
 				editor = newEditor;
-				doc = editor.document;
+				model = editor.model;
+				doc = model.document;
 
 				const command = new DeleteCommand( editor, 'backward' );
 				editor.commands.add( 'delete', command );
 
-				doc.schema.registerItem( 'paragraph', '$block' );
-				doc.schema.registerItem( 'heading1', '$block' );
+				model.schema.registerItem( 'paragraph', '$block' );
+				model.schema.registerItem( 'heading1', '$block' );
 			} );
 	} );
 
@@ -38,23 +39,23 @@ describe( 'DeleteCommand', () => {
 	} );
 
 	describe( 'execute()', () => {
-		it( 'uses enqueueChanges', () => {
-			setData( doc, '<paragraph>foo[]bar</paragraph>' );
+		it( 'uses enqueueChange', () => {
+			setData( model, '<paragraph>foo[]bar</paragraph>' );
 
-			doc.enqueueChanges( () => {
+			model.enqueueChange( () => {
 				editor.execute( 'delete' );
 
 				// We expect that command is executed in enqueue changes block. Since we are already in
 				// an enqueued block, the command execution will be postponed. Hence, no changes.
-				expect( getData( doc ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
+				expect( getData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
 			} );
 
 			// After all enqueued changes are done, the command execution is reflected.
-			expect( getData( doc ) ).to.equal( '<paragraph>fo[]bar</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>fo[]bar</paragraph>' );
 		} );
 
 		it( 'locks buffer when executing', () => {
-			setData( doc, '<paragraph>foo[]bar</paragraph>' );
+			setData( model, '<paragraph>foo[]bar</paragraph>' );
 
 			const buffer = editor.commands.get( 'delete' )._buffer;
 			const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
@@ -67,38 +68,38 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'deletes previous character when selection is collapsed', () => {
-			setData( doc, '<paragraph>foo[]bar</paragraph>' );
+			setData( model, '<paragraph>foo[]bar</paragraph>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>fo[]bar</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>fo[]bar</paragraph>' );
 		} );
 
 		it( 'deletes selection contents', () => {
-			setData( doc, '<paragraph>fo[ob]ar</paragraph>' );
+			setData( model, '<paragraph>fo[ob]ar</paragraph>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
 		} );
 
 		it( 'merges elements', () => {
-			setData( doc, '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
+			setData( model, '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
 		} );
 
 		it( 'does not try to delete when selection is at the boundary', () => {
 			const spy = sinon.spy();
 
 			editor.data.on( 'deleteContent', spy );
-			setData( doc, '<paragraph>[]foo</paragraph>' );
+			setData( model, '<paragraph>[]foo</paragraph>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
 			expect( spy.callCount ).to.equal( 0 );
 		} );
 
@@ -106,7 +107,7 @@ describe( 'DeleteCommand', () => {
 			const spy = sinon.spy();
 
 			editor.data.on( 'modifySelection', spy );
-			setData( doc, '<paragraph>foo[]bar</paragraph>' );
+			setData( model, '<paragraph>foo[]bar</paragraph>' );
 
 			editor.commands.get( 'delete' ).direction = 'forward';
 
@@ -123,13 +124,13 @@ describe( 'DeleteCommand', () => {
 			const spy = sinon.spy();
 
 			editor.data.on( 'deleteContent', spy );
-			setData( doc, '<paragraph>foo[]bar</paragraph>' );
+			setData( model, '<paragraph>foo[]bar</paragraph>' );
 
 			editor.execute( 'delete' );
 
 			expect( spy.callCount ).to.equal( 1 );
 
-			const deleteOpts = spy.args[ 0 ][ 1 ][ 2 ];
+			const deleteOpts = spy.args[ 0 ][ 1 ][ 1 ];
 			expect( deleteOpts ).to.have.property( 'doNotResetEntireContent', true );
 		} );
 
@@ -137,30 +138,30 @@ describe( 'DeleteCommand', () => {
 			const spy = sinon.spy();
 
 			editor.data.on( 'deleteContent', spy );
-			setData( doc, '<paragraph>[foobar]</paragraph>' );
+			setData( model, '<paragraph>[foobar]</paragraph>' );
 
 			editor.execute( 'delete' );
 
 			expect( spy.callCount ).to.equal( 1 );
 
-			const deleteOpts = spy.args[ 0 ][ 1 ][ 2 ];
+			const deleteOpts = spy.args[ 0 ][ 1 ][ 1 ];
 			expect( deleteOpts ).to.have.property( 'doNotResetEntireContent', false );
 		} );
 
 		it( 'leaves an empty paragraph after removing the whole content from editor', () => {
-			setData( doc, '<heading1>[Header 1</heading1><paragraph>Some text.]</paragraph>' );
+			setData( model, '<heading1>[Header 1</heading1><paragraph>Some text.]</paragraph>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
 		} );
 
 		it( 'leaves an empty paragraph after removing the whole content inside limit element', () => {
-			doc.schema.registerItem( 'section', '$root' );
-			doc.schema.limits.add( 'section' );
-			doc.schema.allow( { name: 'section', inside: '$root' } );
+			model.schema.registerItem( 'section', '$root' );
+			model.schema.limits.add( 'section' );
+			model.schema.allow( { name: 'section', inside: '$root' } );
 
-			setData( doc,
+			setData( model,
 				'<heading1>Foo</heading1>' +
 					'<section>' +
 						'<heading1>[Header 1</heading1>' +
@@ -171,7 +172,7 @@ describe( 'DeleteCommand', () => {
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal(
+			expect( getData( model ) ).to.equal(
 				'<heading1>Foo</heading1>' +
 				'<section>' +
 					'<paragraph>[]</paragraph>' +
@@ -181,51 +182,51 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'leaves an empty paragraph after removing another paragraph from block element', () => {
-			doc.schema.registerItem( 'section', '$block' );
-			doc.schema.registerItem( 'blockQuote', '$block' );
-			doc.schema.limits.add( 'section' );
-			doc.schema.allow( { name: 'section', inside: '$root' } );
-			doc.schema.allow( { name: 'paragraph', inside: 'section' } );
-			doc.schema.allow( { name: 'blockQuote', inside: 'section' } );
-			doc.schema.allow( { name: 'paragraph', inside: 'blockQuote' } );
+			model.schema.registerItem( 'section', '$block' );
+			model.schema.registerItem( 'blockQuote', '$block' );
+			model.schema.limits.add( 'section' );
+			model.schema.allow( { name: 'section', inside: '$root' } );
+			model.schema.allow( { name: 'paragraph', inside: 'section' } );
+			model.schema.allow( { name: 'blockQuote', inside: 'section' } );
+			model.schema.allow( { name: 'paragraph', inside: 'blockQuote' } );
 
-			setData( doc, '<section><blockQuote><paragraph>[]</paragraph></blockQuote></section>' );
+			setData( model, '<section><blockQuote><paragraph>[]</paragraph></blockQuote></section>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<section><paragraph>[]</paragraph></section>' );
+			expect( getData( model ) ).to.equal( '<section><paragraph>[]</paragraph></section>' );
 		} );
 
 		it( 'leaves an empty paragraph after removing the whole content when root element was not added as Schema.limits', () => {
-			doc.schema.limits.delete( '$root' );
+			model.schema.limits.delete( '$root' );
 
-			setData( doc, '<heading1>[]</heading1>' );
+			setData( model, '<heading1>[]</heading1>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
 		} );
 
 		it( 'replaces an empty element with paragraph', () => {
-			setData( doc, '<heading1>[]</heading1>' );
+			setData( model, '<heading1>[]</heading1>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<paragraph>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
 		} );
 
 		it( 'does not replace an element when Backspace or Delete key is held', () => {
-			setData( doc, '<heading1>Bar[]</heading1>' );
+			setData( model, '<heading1>Bar[]</heading1>' );
 
 			for ( let sequence = 1; sequence < 10; ++sequence ) {
 				editor.execute( 'delete', { sequence } );
 			}
 
-			expect( getData( doc ) ).to.equal( '<heading1>[]</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
 		} );
 
 		it( 'does not replace with paragraph in another paragraph already occurs in limit element', () => {
-			setData( doc, '<paragraph>[]</paragraph>' );
+			setData( model, '<paragraph>[]</paragraph>' );
 
 			const element = doc.getRoot().getNodeByPath( [ 0 ] );
 
@@ -235,13 +236,13 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'does not replace an element if a paragraph is not allowed in current position', () => {
-			doc.schema.disallow( { name: 'paragraph', inside: '$root' } );
+			model.schema.disallow( { name: 'paragraph', inside: '$root' } );
 
-			setData( doc, '<heading1>[]</heading1>' );
+			setData( model, '<heading1>[]</heading1>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc ) ).to.equal( '<heading1>[]</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
 		} );
 	} );
 } );

+ 33 - 34
packages/ckeditor5-typing/tests/input.js

@@ -14,7 +14,7 @@ import Italic from '@ckeditor/ckeditor5-basic-styles/src/italicengine';
 import LinkEngine from '@ckeditor/ckeditor5-link/src/linkengine';
 import Input from '../src/input';
 
-import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
+import Writer from '@ckeditor/ckeditor5-engine/src/model/writer';
 import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
 import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
 import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
@@ -45,7 +45,7 @@ describe( 'Input feature', () => {
 			} )
 			.then( newEditor => {
 				// Mock image feature.
-				newEditor.document.schema.registerItem( 'image', '$inline' );
+				newEditor.model.schema.registerItem( 'image', '$inline' );
 
 				buildModelConverter().for( newEditor.data.modelToView, newEditor.editing.modelToView )
 					.fromElement( 'image' )
@@ -56,8 +56,8 @@ describe( 'Input feature', () => {
 					.toElement( 'image' );
 
 				editor = newEditor;
-				model = editor.editing.model;
-				modelRoot = model.getRoot();
+				model = editor.model;
+				modelRoot = model.document.getRoot();
 				view = editor.editing.view;
 				viewRoot = view.getRoot();
 			} );
@@ -70,8 +70,8 @@ describe( 'Input feature', () => {
 	beforeEach( () => {
 		editor.setData( '<p>foobar</p>' );
 
-		model.enqueueChanges( () => {
-			model.selection.setRanges( [
+		model.change( () => {
+			model.document.selection.setRanges( [
 				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 3, modelRoot.getChild( 0 ), 3 )
 			] );
 		} );
@@ -133,7 +133,6 @@ describe( 'Input feature', () => {
 					italic: true
 				}
 			} );
-
 			view.fire( 'mutations', [
 				{
 					type: 'children',
@@ -294,8 +293,8 @@ describe( 'Input feature', () => {
 			const viewSelection = new ViewSelection();
 			viewSelection.setCollapsedAt( viewRoot.getChild( 0 ).getChild( 0 ), 6 );
 
-			testUtils.sinon.spy( Batch.prototype, 'insert' );
-			testUtils.sinon.spy( Batch.prototype, 'remove' );
+			testUtils.sinon.spy( Writer.prototype, 'insert' );
+			testUtils.sinon.spy( Writer.prototype, 'remove' );
 
 			view.fire( 'mutations',
 				[ {
@@ -307,8 +306,8 @@ describe( 'Input feature', () => {
 				viewSelection
 			);
 
-			expect( Batch.prototype.insert.calledOnce ).to.be.true;
-			expect( Batch.prototype.remove.calledOnce ).to.be.true;
+			expect( Writer.prototype.insert.calledOnce ).to.be.true;
+			expect( Writer.prototype.remove.calledOnce ).to.be.true;
 		} );
 
 		it( 'should place selection after when correcting to longer word (spellchecker)', () => {
@@ -396,8 +395,8 @@ describe( 'Input feature', () => {
 		} );
 
 		it( 'should replace last &nbsp; with space', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
 				] );
 			} );
@@ -416,8 +415,8 @@ describe( 'Input feature', () => {
 		} );
 
 		it( 'should replace first &nbsp; with space', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 0, modelRoot.getChild( 0 ), 0 )
 				] );
 			} );
@@ -436,8 +435,8 @@ describe( 'Input feature', () => {
 		} );
 
 		it( 'should replace all &nbsp; with spaces', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
 				] );
 			} );
@@ -458,8 +457,8 @@ describe( 'Input feature', () => {
 
 	describe( 'keystroke handling', () => {
 		it( 'should remove contents', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -492,8 +491,8 @@ describe( 'Input feature', () => {
 		} );
 
 		it( 'should do nothing on arrow key', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -503,8 +502,8 @@ describe( 'Input feature', () => {
 		} );
 
 		it( 'should do nothing on ctrl combinations', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -514,8 +513,8 @@ describe( 'Input feature', () => {
 		} );
 
 		it( 'should do nothing on non printable keys', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -528,8 +527,8 @@ describe( 'Input feature', () => {
 
 		// #69
 		it( 'should do nothing on tab key', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -540,8 +539,8 @@ describe( 'Input feature', () => {
 
 		// #82
 		it( 'should do nothing on composition start key', () => {
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -561,8 +560,8 @@ describe( 'Input feature', () => {
 			const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
 			const unlockSpy = testUtils.sinon.spy( buffer, 'unlock' );
 
-			model.enqueueChanges( () => {
-				model.selection.setRanges( [
+			model.change( () => {
+				model.document.selection.setRanges( [
 					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) ] );
 			} );
 
@@ -637,14 +636,14 @@ describe( 'Input feature', () => {
 			return ClassicTestEditor.create( domElement, { plugins: [ Input, Paragraph, Bold, Italic, LinkEngine ] } )
 				.then( newEditor => {
 					editor = newEditor;
-					model = editor.document;
-					modelRoot = model.getRoot();
+					model = editor.model;
+					modelRoot = model.document.getRoot();
 					view = editor.editing.view;
 					viewRoot = view.getRoot();
 					domRoot = view.getDomRoot();
 
 					// Mock image feature.
-					newEditor.document.schema.registerItem( 'image', '$inline' );
+					newEditor.model.schema.registerItem( 'image', '$inline' );
 
 					buildModelConverter().for( newEditor.data.modelToView, newEditor.editing.modelToView )
 						.fromElement( 'image' )

+ 9 - 8
packages/ckeditor5-typing/tests/inputcommand-integration.js

@@ -21,7 +21,7 @@ import { setData as setModelData, getData as getModelData } from '@ckeditor/cked
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
 describe( 'Typing – InputCommand integration', () => {
-	let editor, doc, viewDocument, boldView, italicView, editorElement;
+	let editor, model, doc, viewDocument, boldView, italicView, editorElement;
 
 	beforeEach( () => {
 		editorElement = document.createElement( 'div' );
@@ -34,7 +34,8 @@ describe( 'Typing – InputCommand integration', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				doc = editor.document;
+				model = editor.model;
+				doc = model.document;
 				viewDocument = editor.editing.view;
 
 				boldView = editor.ui.componentFactory.create( 'bold' );
@@ -49,7 +50,7 @@ describe( 'Typing – InputCommand integration', () => {
 	} );
 
 	function expectOutput( modelOutput, viewOutput ) {
-		expect( getModelData( editor.document ) ).to.equal( modelOutput );
+		expect( getModelData( model ) ).to.equal( modelOutput );
 		expect( getViewData( viewDocument ) ).to.equal( viewOutput );
 	}
 
@@ -77,7 +78,7 @@ describe( 'Typing – InputCommand integration', () => {
 
 	describe( 'InputCommand integration', () => {
 		it( 'resets the buffer on typing respecting typing.undoStep', () => {
-			setModelData( doc, '<paragraph>0[]</paragraph>' );
+			setModelData( model, '<paragraph>0[]</paragraph>' );
 
 			simulateTyping( '123456789' );
 
@@ -97,7 +98,7 @@ describe( 'Typing – InputCommand integration', () => {
 		} );
 
 		it( 'resets the buffer on text insertion respecting typing.undoStep', () => {
-			setModelData( doc, '<paragraph>0[]</paragraph>' );
+			setModelData( model, '<paragraph>0[]</paragraph>' );
 
 			simulateBatches( [ '1234', '5', '678', '9' ] );
 
@@ -117,7 +118,7 @@ describe( 'Typing – InputCommand integration', () => {
 		} );
 
 		it( 'resets the buffer when selection changes', () => {
-			setModelData( doc, '<paragraph>Foo[] Bar</paragraph>' );
+			setModelData( model, '<paragraph>Foo[] Bar</paragraph>' );
 
 			setSelection( [ 0, 5 ], [ 0, 5 ] );
 			simulateTyping( '1' );
@@ -141,7 +142,7 @@ describe( 'Typing – InputCommand integration', () => {
 		} );
 
 		it( 'resets the buffer when selection changes (with enter)', () => {
-			setModelData( doc, '<paragraph>Foo[]Bar</paragraph>' );
+			setModelData( model, '<paragraph>Foo[]Bar</paragraph>' );
 
 			simulateTyping( '1' );
 			editor.execute( 'enter' );
@@ -177,7 +178,7 @@ describe( 'Typing – InputCommand integration', () => {
 		} );
 
 		it( 'resets the buffer when attribute changes', () => {
-			setModelData( doc, '<paragraph>Foo[] Bar</paragraph>' );
+			setModelData( model, '<paragraph>Foo[] Bar</paragraph>' );
 
 			simulateTyping( ' ' );
 

+ 40 - 39
packages/ckeditor5-typing/tests/inputcommand.js

@@ -14,7 +14,7 @@ import ChangeBuffer from '../src/changebuffer';
 import Input from '../src/input';
 
 describe( 'InputCommand', () => {
-	let editor, doc, buffer;
+	let editor, model, doc, buffer;
 
 	testUtils.createSinonSandbox();
 
@@ -22,7 +22,8 @@ describe( 'InputCommand', () => {
 		return ModelTestEditor.create()
 			.then( newEditor => {
 				editor = newEditor;
-				doc = editor.document;
+				model = editor.model;
+				doc = model.document;
 
 				const inputCommand = new InputCommand( editor, 20 );
 				editor.commands.add( 'input', inputCommand );
@@ -30,8 +31,8 @@ describe( 'InputCommand', () => {
 				buffer = inputCommand.buffer;
 				buffer.size = 0;
 
-				doc.schema.registerItem( 'p', '$block' );
-				doc.schema.registerItem( 'h1', '$block' );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.registerItem( 'h1', '$block' );
 			} );
 	} );
 
@@ -63,23 +64,23 @@ describe( 'InputCommand', () => {
 	} );
 
 	describe( 'execute()', () => {
-		it( 'uses enqueueChanges', () => {
-			setData( doc, '<p>foo[]bar</p>' );
+		it( 'uses enqueueChange', () => {
+			setData( model, '<p>foo[]bar</p>' );
 
-			doc.enqueueChanges( () => {
+			model.enqueueChange( () => {
 				editor.execute( 'input', { text: 'x' } );
 
 				// We expect that command is executed in enqueue changes block. Since we are already in
 				// an enqueued block, the command execution will be postponed. Hence, no changes.
-				expect( getData( doc ) ).to.be.equal( '<p>foo[]bar</p>' );
+				expect( getData( model ) ).to.be.equal( '<p>foo[]bar</p>' );
 			} );
 
 			// After all enqueued changes are done, the command execution is reflected.
-			expect( getData( doc ) ).to.be.equal( '<p>foox[]bar</p>' );
+			expect( getData( model ) ).to.be.equal( '<p>foox[]bar</p>' );
 		} );
 
 		it( 'should lock and unlock buffer', () => {
-			setData( doc, '<p>foo[]bar</p>' );
+			setData( model, '<p>foo[]bar</p>' );
 
 			const spyLock = testUtils.sinon.spy( buffer, 'lock' );
 			const spyUnlock = testUtils.sinon.spy( buffer, 'unlock' );
@@ -93,132 +94,132 @@ describe( 'InputCommand', () => {
 		} );
 
 		it( 'inserts text for collapsed range', () => {
-			setData( doc, '<p>foo[]</p>' );
+			setData( model, '<p>foo[]</p>' );
 
 			editor.execute( 'input', {
 				text: 'bar',
-				range: editor.document.selection.getFirstRange()
+				range: doc.selection.getFirstRange()
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>foobar[]</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>foobar[]</p>' );
 			expect( buffer.size ).to.be.equal( 3 );
 		} );
 
 		it( 'replaces text for range within single element on the beginning', () => {
-			setData( doc, '<p>[fooba]r</p>' );
+			setData( model, '<p>[fooba]r</p>' );
 
 			editor.execute( 'input', {
 				text: 'rab',
-				range: editor.document.selection.getFirstRange()
+				range: doc.selection.getFirstRange()
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>rab[]r</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>rab[]r</p>' );
 			expect( buffer.size ).to.be.equal( 3 );
 		} );
 
 		it( 'replaces text for range within single element in the middle', () => {
-			setData( doc, '<p>fo[oba]r</p>' );
+			setData( model, '<p>fo[oba]r</p>' );
 
 			editor.execute( 'input', {
 				text: 'bazz',
-				range: editor.document.selection.getFirstRange()
+				range: doc.selection.getFirstRange()
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>fobazz[]r</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>fobazz[]r</p>' );
 			expect( buffer.size ).to.be.equal( 4 );
 		} );
 
 		it( 'replaces text for range within single element on the end', () => {
-			setData( doc, '<p>fooba[r]</p>' );
+			setData( model, '<p>fooba[r]</p>' );
 
 			editor.execute( 'input', {
 				text: 'zzz',
-				range: editor.document.selection.getFirstRange()
+				range: doc.selection.getFirstRange()
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>foobazzz[]</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>foobazzz[]</p>' );
 			expect( buffer.size ).to.be.equal( 3 );
 		} );
 
 		it( 'replaces text for range within multiple elements', () => {
-			setData( doc, '<h1>F[OO</h1><p>b]ar</p>' );
+			setData( model, '<h1>F[OO</h1><p>b]ar</p>' );
 
 			editor.execute( 'input', {
 				text: 'unny c',
-				range: editor.document.selection.getFirstRange()
+				range: doc.selection.getFirstRange()
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<h1>Funny c[</h1><p>]ar</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<h1>Funny c[</h1><p>]ar</p>' );
 			expect( buffer.size ).to.be.equal( 6 );
 		} );
 
 		it( 'uses current selection when range is not given', () => {
-			setData( doc, '<p>foob[ar]</p>' );
+			setData( model, '<p>foob[ar]</p>' );
 
 			editor.execute( 'input', {
 				text: 'az'
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>foobaz[]</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>foobaz[]</p>' );
 			expect( buffer.size ).to.be.equal( 2 );
 		} );
 
 		it( 'only removes content when empty text given', () => {
-			setData( doc, '<p>[fo]obar</p>' );
+			setData( model, '<p>[fo]obar</p>' );
 
 			editor.execute( 'input', {
 				text: '',
-				range: editor.document.selection.getFirstRange()
+				range: doc.selection.getFirstRange()
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>[]obar</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>[]obar</p>' );
 			expect( buffer.size ).to.be.equal( 0 );
 		} );
 
 		it( 'should set selection according to passed resultRange (collapsed)', () => {
-			setData( doc, '<p>[foo]bar</p>' );
+			setData( model, '<p>[foo]bar</p>' );
 
 			editor.execute( 'input', {
 				text: 'new',
 				resultRange: new Range( new Position( doc.getRoot(), [ 0, 5 ] ) )
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>newba[]r</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>newba[]r</p>' );
 			expect( buffer.size ).to.be.equal( 3 );
 		} );
 
 		it( 'should set selection according to passed resultRange (non-collapsed)', () => {
-			setData( doc, '<p>[foo]bar</p>' );
+			setData( model, '<p>[foo]bar</p>' );
 
 			editor.execute( 'input', {
 				text: 'new',
 				resultRange: new Range( new Position( doc.getRoot(), [ 0, 3 ] ), new Position( doc.getRoot(), [ 0, 6 ] ) )
 			} );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>new[bar]</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>new[bar]</p>' );
 			expect( buffer.size ).to.be.equal( 3 );
 		} );
 
 		it( 'only removes content when no text given (with default non-collapsed range)', () => {
-			setData( doc, '<p>[fo]obar</p>' );
+			setData( model, '<p>[fo]obar</p>' );
 
 			editor.execute( 'input' );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>[]obar</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>[]obar</p>' );
 			expect( buffer.size ).to.be.equal( 0 );
 		} );
 
 		it( 'does not change selection and content when no text given (with default collapsed range)', () => {
-			setData( doc, '<p>fo[]obar</p>' );
+			setData( model, '<p>fo[]obar</p>' );
 
 			editor.execute( 'input' );
 
-			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>fo[]obar</p>' );
+			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>fo[]obar</p>' );
 			expect( buffer.size ).to.be.equal( 0 );
 		} );
 
 		it( 'does not create insert delta when no text given', () => {
-			setData( doc, '<p>foo[]bar</p>' );
+			setData( model, '<p>foo[]bar</p>' );
 
 			const version = doc.version;
 

+ 1 - 1
packages/ckeditor5-typing/tests/manual/52/1.js

@@ -14,7 +14,7 @@ import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 window.setInterval( function() {
-	console.log( getData( window.editor.document ) );
+	console.log( getData( window.editor.model.document ) );
 }, 3000 );
 
 ClassicEditor

+ 1 - 1
packages/ckeditor5-typing/tests/manual/82/1.js

@@ -12,7 +12,7 @@ import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 window.setInterval( function() {
-	console.log( getData( window.editor.document ) );
+	console.log( getData( window.editor.model.document ) );
 }, 3000 );
 
 ClassicEditor

+ 1 - 1
packages/ckeditor5-typing/tests/manual/86/1.js

@@ -11,7 +11,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 window.setInterval( function() {
-	console.log( getData( window.editor.document ) );
+	console.log( getData( window.editor.model.document ) );
 }, 3000 );
 
 ClassicEditor

+ 1 - 1
packages/ckeditor5-typing/tests/manual/delete.js

@@ -16,7 +16,7 @@ import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 window.getData = getData;
 
 window.setInterval( function() {
-	console.log( getData( window.editor.document ) );
+	console.log( getData( window.editor.model.document ) );
 }, 3000 );
 
 ClassicEditor

+ 1 - 1
packages/ckeditor5-typing/tests/manual/input.js

@@ -14,7 +14,7 @@ import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 window.setInterval( function() {
-	console.log( getData( window.editor.document ) );
+	console.log( getData( window.editor.model.document ) );
 }, 3000 );
 
 ClassicEditor

+ 6 - 6
packages/ckeditor5-typing/tests/manual/nbsp.js

@@ -20,21 +20,21 @@ ClassicEditor
 	.then( editor => {
 		window.editor = editor;
 
-		editor.document.schema.allow( { name: '$text', inside: '$root' } );
+		editor.model.schema.allow( { name: '$text', inside: '$root' } );
 
 		const editable = editor.ui.view.editableElement;
 
 		document.querySelector( '#nbsp' ).addEventListener( 'click', () => {
-			editor.document.enqueueChanges( () => {
-				editor.document.selection.collapseToStart();
-				editor.document.batch().insertText( '\u00A0', editor.document.selection.getFirstPosition() );
+			editor.model.change( writer => {
+				editor.model.document.selection.collapseToStart();
+				writer.insertText( '\u00A0', editor.model.document.selection.getFirstPosition() );
 			} );
 		} );
 
-		editor.document.on( 'changesDone', () => {
+		editor.model.document.on( 'changesDone', () => {
 			console.clear();
 
-			const modelData = getModelData( editor.document, { withoutSelection: true } );
+			const modelData = getModelData( editor.model.document, { withoutSelection: true } );
 			console.log( 'model:', modelData.replace( /\u00A0/g, '&nbsp;' ) );
 
 			const viewData = getViewData( editor.editing.view, { withoutSelection: true } );

+ 1 - 1
packages/ckeditor5-typing/tests/manual/spellchecking.js

@@ -14,7 +14,7 @@ import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 window.setInterval( function() {
-	console.log( getData( window.editor.document ) );
+	console.log( getData( window.editor.model.document ) );
 }, 3000 );
 
 ClassicEditor.create( document.querySelector( '#editor' ), {

+ 7 - 7
packages/ckeditor5-typing/tests/spellchecking.js

@@ -43,7 +43,7 @@ describe( 'Typing – spellchecking integration', () => {
 
 	beforeEach( () => {
 		if ( onChangesDone ) {
-			editor.document.off( 'changesDone', onChangesDone );
+			editor.model.document.off( 'changesDone', onChangesDone );
 			onChangesDone = null;
 		}
 
@@ -250,24 +250,24 @@ function emulateSpellcheckerMutation( editor, nodeIndex, resultPositionIndex, ol
 }
 
 function emulateSpellcheckerInsertText( editor, nodeIndex, rangeStart, rangeEnd, text, onChangesDoneCallback ) {
-	const model = editor.editing.model;
-	const modelRoot = model.getRoot();
+	const model = editor.model;
+	const modelRoot = model.document.getRoot();
 
 	editor.editing.view.focus();
 
-	model.enqueueChanges( () => {
-		model.selection.setRanges( [
+	model.change( () => {
+		model.document.selection.setRanges( [
 			ModelRange.createFromParentsAndOffsets( modelRoot.getChild( nodeIndex ), rangeStart, modelRoot.getChild( nodeIndex ), rangeEnd )
 		] );
 	} );
 
-	editor.document.once( 'changesDone', onChangesDoneCallback, { priority: 'low' } );
+	editor.model.document.once( 'changesDone', onChangesDoneCallback, { priority: 'low' } );
 
 	window.document.execCommand( 'insertText', false, text );
 }
 
 function expectContent( editor, expectedModel, expectedView ) {
-	expect( getModelData( editor.editing.model ) ).to.equal( expectedModel );
+	expect( getModelData( editor.model ) ).to.equal( expectedModel );
 	expect( getViewData( editor.editing.view ) ).to.equal( expectedView );
 }
 

+ 6 - 6
packages/ckeditor5-typing/tests/tickets/59.js

@@ -35,12 +35,12 @@ describe( 'Bug ckeditor5-typing#59', () => {
 	} );
 
 	it( 'editor does not blow up when deleting last styled character', () => {
-		editor.document.enqueueChanges( () => {
+		editor.model.change( () => {
 			editor.editing.view.getDomRoot().focus();
-			setData( editor.document, '<paragraph><$text bold="true">foo</$text> x <$text bold="true">bar</$text>.[]</paragraph>' );
+			setData( editor.model, '<paragraph><$text bold="true">foo</$text> x <$text bold="true">bar</$text>.[]</paragraph>' );
 		} );
 
-		while ( editor.document.selection.anchor.offset > 0 ) {
+		while ( editor.model.document.selection.anchor.offset > 0 ) {
 			editor.execute( 'delete' );
 		}
 
@@ -50,12 +50,12 @@ describe( 'Bug ckeditor5-typing#59', () => {
 	// This is something that came to my mind after I worked on ckeditor/ckeditor5-engine#659.
 	// Toggling bold at the end creates a lot of weird cases so it's interesting to see if it works... and it didn't back then.
 	it( 'editor does not blow up when deleting last styled character, forcing bold switch', () => {
-		editor.document.enqueueChanges( () => {
+		editor.model.change( () => {
 			editor.editing.view.getDomRoot().focus();
-			setData( editor.document, '<paragraph><$text bold="true">foo</$text> x <$text bold="true">bar</$text>.[]</paragraph>' );
+			setData( editor.model, '<paragraph><$text bold="true">foo</$text> x <$text bold="true">bar</$text>.[]</paragraph>' );
 		} );
 
-		while ( editor.document.selection.anchor.offset > 0 ) {
+		while ( editor.model.document.selection.anchor.offset > 0 ) {
 			editor.execute( 'delete' );
 			editor.execute( 'bold' );
 		}