Browse Source

Merge branch t/engine/1186

Internal: Update API usage after merge t/1186 on engine.
Piotr Jasiun 8 years ago
parent
commit
f7d58da1a6

+ 12 - 14
packages/ckeditor5-link/src/linkcommand.js

@@ -30,10 +30,11 @@ export default class LinkCommand extends Command {
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
 	refresh() {
 	refresh() {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = model.document;
 
 
 		this.value = doc.selection.getAttribute( 'linkHref' );
 		this.value = doc.selection.getAttribute( 'linkHref' );
-		this.isEnabled = doc.schema.checkAttributeInSelection( doc.selection, 'linkHref' );
+		this.isEnabled = model.schema.checkAttributeInSelection( doc.selection, 'linkHref' );
 	}
 	}
 
 
 	/**
 	/**
@@ -53,13 +54,10 @@ export default class LinkCommand extends Command {
 	 * @param {String} href Link destination.
 	 * @param {String} href Link destination.
 	 */
 	 */
 	execute( href ) {
 	execute( href ) {
-		const doc = this.editor.document;
-		const selection = doc.selection;
-
-		doc.enqueueChanges( () => {
-			// Keep it as one undo step.
-			const batch = doc.batch();
+		const model = this.editor.model;
+		const selection = model.document.selection;
 
 
+		model.change( writer => {
 			// If selection is collapsed then update selected link or insert new one at the place of caret.
 			// If selection is collapsed then update selected link or insert new one at the place of caret.
 			if ( selection.isCollapsed ) {
 			if ( selection.isCollapsed ) {
 				const position = selection.getFirstPosition();
 				const position = selection.getFirstPosition();
@@ -69,20 +67,20 @@ export default class LinkCommand extends Command {
 					// Then update `linkHref` value.
 					// Then update `linkHref` value.
 					const linkRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
 					const linkRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
 
 
-					batch.setAttribute( 'linkHref', href, linkRange );
+					writer.setAttribute( 'linkHref', href, linkRange );
 
 
 					// Create new range wrapping changed link.
 					// Create new range wrapping changed link.
 					selection.setRanges( [ linkRange ] );
 					selection.setRanges( [ linkRange ] );
 				}
 				}
 				// If not then insert text node with `linkHref` attribute in place of caret.
 				// If not then insert text node with `linkHref` attribute in place of caret.
 				else {
 				else {
-					const attributes = toMap( doc.selection.getAttributes() );
+					const attributes = toMap( selection.getAttributes() );
 
 
 					attributes.set( 'linkHref', href );
 					attributes.set( 'linkHref', href );
 
 
-					const node = batch.createText( href, attributes );
+					const node = writer.createText( href, attributes );
 
 
-					batch.insert( node, position );
+					writer.insert( node, position );
 
 
 					// Create new range wrapping created node.
 					// Create new range wrapping created node.
 					selection.setRanges( [ Range.createOn( node ) ] );
 					selection.setRanges( [ Range.createOn( node ) ] );
@@ -90,10 +88,10 @@ export default class LinkCommand extends Command {
 			} else {
 			} else {
 				// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges
 				// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges
 				// omitting nodes where `linkHref` attribute is disallowed.
 				// omitting nodes where `linkHref` attribute is disallowed.
-				const ranges = doc.schema.getValidRanges( selection.getRanges(), 'linkHref' );
+				const ranges = model.schema.getValidRanges( selection.getRanges(), 'linkHref' );
 
 
 				for ( const range of ranges ) {
 				for ( const range of ranges ) {
-					batch.setAttribute( 'linkHref', href, range );
+					writer.setAttribute( 'linkHref', href, range );
 				}
 				}
 			}
 			}
 		} );
 		} );

+ 2 - 2
packages/ckeditor5-link/src/linkengine.js

@@ -31,9 +31,9 @@ export default class LinkEngine extends Plugin {
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
 		// Allow link attribute on all inline nodes.
 		// Allow link attribute on all inline nodes.
-		editor.document.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$block' } );
+		editor.model.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$block' } );
 		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
 		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.document.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } );
+		editor.model.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } );
 
 
 		// Build converter from model to view for data and editing pipelines.
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 5 - 8
packages/ckeditor5-link/src/unlinkcommand.js

@@ -20,7 +20,7 @@ export default class UnlinkCommand extends Command {
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
 	refresh() {
 	refresh() {
-		this.isEnabled = this.editor.document.selection.hasAttribute( 'linkHref' );
+		this.isEnabled = this.editor.model.document.selection.hasAttribute( 'linkHref' );
 	}
 	}
 
 
 	/**
 	/**
@@ -32,20 +32,17 @@ export default class UnlinkCommand extends Command {
 	 * @fires execute
 	 * @fires execute
 	 */
 	 */
 	execute() {
 	execute() {
-		const document = this.editor.document;
-		const selection = document.selection;
+		const model = this.editor.model;
+		const selection = model.document.selection;
 
 
-		document.enqueueChanges( () => {
+		model.change( writer => {
 			// Get ranges to unlink.
 			// Get ranges to unlink.
 			const rangesToUnlink = selection.isCollapsed ?
 			const rangesToUnlink = selection.isCollapsed ?
 				[ findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) ) ] : selection.getRanges();
 				[ findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) ) ] : selection.getRanges();
 
 
-			// Keep it as one undo step.
-			const batch = document.batch();
-
 			// Remove `linkHref` attribute from specified ranges.
 			// Remove `linkHref` attribute from specified ranges.
 			for ( const range of rangesToUnlink ) {
 			for ( const range of rangesToUnlink ) {
-				batch.removeAttribute( 'linkHref', range );
+				writer.removeAttribute( 'linkHref', range );
 			}
 			}
 		} );
 		} );
 	}
 	}

+ 16 - 15
packages/ckeditor5-link/tests/findlinkrange.js

@@ -4,23 +4,24 @@
  */
  */
 
 
 import findLinkRange from '../src/findlinkrange';
 import findLinkRange from '../src/findlinkrange';
-import Document from '@ckeditor/ckeditor5-engine/src/model/document';
+import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 
 describe( 'findLinkRange', () => {
 describe( 'findLinkRange', () => {
-	let document, root;
+	let model, document, root;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
-		document = new Document();
+		model = new Model();
+		document = model.document;
 		root = document.createRoot();
 		root = document.createRoot();
-		document.schema.allow( { name: '$text', inside: '$root' } );
-		document.schema.registerItem( 'p', '$block' );
+		model.schema.allow( { name: '$text', inside: '$root' } );
+		model.schema.registerItem( 'p', '$block' );
 	} );
 	} );
 
 
 	it( 'should find link range searching from the center of the link #1', () => {
 	it( 'should find link range searching from the center of the link #1', () => {
-		setData( document, '<$text linkHref="url">foobar</$text>' );
+		setData( model, '<$text linkHref="url">foobar</$text>' );
 
 
 		const startPosition = new Position( root, [ 3 ] );
 		const startPosition = new Position( root, [ 3 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -30,7 +31,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range searching from the center of the link #2', () => {
 	it( 'should find link range searching from the center of the link #2', () => {
-		setData( document, 'abc <$text linkHref="url">foobar</$text> abc' );
+		setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
 
 
 		const startPosition = new Position( root, [ 7 ] );
 		const startPosition = new Position( root, [ 7 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -40,7 +41,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range searching from the beginning of the link #1', () => {
 	it( 'should find link range searching from the beginning of the link #1', () => {
-		setData( document, '<$text linkHref="url">foobar</$text>' );
+		setData( model, '<$text linkHref="url">foobar</$text>' );
 
 
 		const startPosition = new Position( root, [ 0 ] );
 		const startPosition = new Position( root, [ 0 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -50,7 +51,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range searching from the beginning of the link #2', () => {
 	it( 'should find link range searching from the beginning of the link #2', () => {
-		setData( document, 'abc <$text linkHref="url">foobar</$text> abc' );
+		setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
 
 
 		const startPosition = new Position( root, [ 4 ] );
 		const startPosition = new Position( root, [ 4 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -60,7 +61,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range searching from the end of the link #1', () => {
 	it( 'should find link range searching from the end of the link #1', () => {
-		setData( document, '<$text linkHref="url">foobar</$text>' );
+		setData( model, '<$text linkHref="url">foobar</$text>' );
 
 
 		const startPosition = new Position( root, [ 6 ] );
 		const startPosition = new Position( root, [ 6 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -70,7 +71,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range searching from the end of the link #2', () => {
 	it( 'should find link range searching from the end of the link #2', () => {
-		setData( document, 'abc <$text linkHref="url">foobar</$text> abc' );
+		setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
 
 
 		const startPosition = new Position( root, [ 10 ] );
 		const startPosition = new Position( root, [ 10 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -80,7 +81,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range when link stick to other link searching from the center of the link', () => {
 	it( 'should find link range when link stick to other link searching from the center of the link', () => {
-		setData( document, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
+		setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
 
 
 		const startPosition = new Position( root, [ 6 ] );
 		const startPosition = new Position( root, [ 6 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -90,7 +91,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range when link stick to other link searching from the beginning of the link', () => {
 	it( 'should find link range when link stick to other link searching from the beginning of the link', () => {
-		setData( document, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
+		setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
 
 
 		const startPosition = new Position( root, [ 3 ] );
 		const startPosition = new Position( root, [ 3 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -100,7 +101,7 @@ describe( 'findLinkRange', () => {
 	} );
 	} );
 
 
 	it( 'should find link range when link stick to other link searching from the end of the link', () => {
 	it( 'should find link range when link stick to other link searching from the end of the link', () => {
-		setData( document, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
+		setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
 
 
 		const startPosition = new Position( root, [ 9 ] );
 		const startPosition = new Position( root, [ 9 ] );
 		const result = findLinkRange( startPosition, 'url' );
 		const result = findLinkRange( startPosition, 'url' );
@@ -111,7 +112,7 @@ describe( 'findLinkRange', () => {
 
 
 	it( 'should find link range only inside current parent', () => {
 	it( 'should find link range only inside current parent', () => {
 		setData(
 		setData(
-			document,
+			model,
 			'<p><$text linkHref="url">foobar</$text></p>' +
 			'<p><$text linkHref="url">foobar</$text></p>' +
 			'<p><$text linkHref="url">foobar</$text></p>' +
 			'<p><$text linkHref="url">foobar</$text></p>' +
 			'<p><$text linkHref="url">foobar</$text></p>'
 			'<p><$text linkHref="url">foobar</$text></p>'

+ 25 - 25
packages/ckeditor5-link/tests/link.js

@@ -79,7 +79,7 @@ describe( 'Link', () => {
 		} );
 		} );
 
 
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when text fragment is selected', () => {
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when text fragment is selected', () => {
-			setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[o]o</paragraph>' );
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
@@ -94,7 +94,7 @@ describe( 'Link', () => {
 		} );
 		} );
 
 
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when selection is collapsed', () => {
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when selection is collapsed', () => {
-			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
@@ -111,7 +111,7 @@ describe( 'Link', () => {
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the link element when collapsed selection is inside ' +
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the link element when collapsed selection is inside ' +
 			'that link',
 			'that link',
 		() => {
 		() => {
-			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 			const linkElement = editor.editing.view.getDomRoot().querySelector( 'a' );
 			const linkElement = editor.editing.view.getDomRoot().querySelector( 'a' );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
@@ -171,7 +171,7 @@ describe( 'Link', () => {
 		} );
 		} );
 
 
 		it( 'should disable #formView elements when link and unlink commands are disabled', () => {
 		it( 'should disable #formView elements when link and unlink commands are disabled', () => {
-			setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[o]o</paragraph>' );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
 
 
@@ -194,17 +194,17 @@ describe( 'Link', () => {
 
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/53
 		// https://github.com/ckeditor/ckeditor5-link/issues/53
 		it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => {
 		it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => {
-			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
 			expect( formView.unlinkButtonView.isVisible ).to.be.false;
 			expect( formView.unlinkButtonView.isVisible ).to.be.false;
 
 
-			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
 			expect( formView.unlinkButtonView.isVisible ).to.be.true;
 			expect( formView.unlinkButtonView.isVisible ).to.be.true;
 
 
-			setModelData( editor.document, '<paragraph><$text linkHref="url">[fo]o</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">[fo]o</$text></paragraph>' );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
 			expect( formView.unlinkButtonView.isVisible ).to.be.true;
 			expect( formView.unlinkButtonView.isVisible ).to.be.true;
@@ -212,7 +212,7 @@ describe( 'Link', () => {
 
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/78
 		// https://github.com/ckeditor/ckeditor5-link/issues/78
 		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (selected link)', () => {
 		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (selected link)', () => {
-			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 
 			// Mock some leftover value **in DOM**, e.g. after previous editing.
 			// Mock some leftover value **in DOM**, e.g. after previous editing.
 			formView.urlInputView.inputView.element.value = 'leftover';
 			formView.urlInputView.inputView.element.value = 'leftover';
@@ -223,7 +223,7 @@ describe( 'Link', () => {
 
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/123
 		// https://github.com/ckeditor/ckeditor5-link/issues/123
 		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (no link selected)', () => {
 		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (no link selected)', () => {
-			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 
 			linkFeature._showPanel();
 			linkFeature._showPanel();
 			expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
 			expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
@@ -233,7 +233,7 @@ describe( 'Link', () => {
 			it( 'should not duplicate #render listeners', () => {
 			it( 'should not duplicate #render listeners', () => {
 				const viewDocument = editor.editing.view;
 				const viewDocument = editor.editing.view;
 
 
-				setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 
 
@@ -250,7 +250,7 @@ describe( 'Link', () => {
 			it( 'updates the position of the panel – editing a link, then the selection remains in the link upon #render', () => {
 			it( 'updates the position of the panel – editing a link, then the selection remains in the link upon #render', () => {
 				const viewDocument = editor.editing.view;
 				const viewDocument = editor.editing.view;
 
 
-				setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 
 				linkFeature._showPanel();
 				linkFeature._showPanel();
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
@@ -272,7 +272,7 @@ describe( 'Link', () => {
 			it( 'updates the position of the panel – creating a new link, then the selection moved upon #render', () => {
 			it( 'updates the position of the panel – creating a new link, then the selection moved upon #render', () => {
 				const viewDocument = editor.editing.view;
 				const viewDocument = editor.editing.view;
 
 
-				setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 
 				linkFeature._showPanel();
 				linkFeature._showPanel();
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
@@ -294,7 +294,7 @@ describe( 'Link', () => {
 			it( 'hides of the panel – editing a link, then the selection moved out of the link upon #render', () => {
 			it( 'hides of the panel – editing a link, then the selection moved out of the link upon #render', () => {
 				const viewDocument = editor.editing.view;
 				const viewDocument = editor.editing.view;
 
 
-				setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
+				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
 
 
 				linkFeature._showPanel();
 				linkFeature._showPanel();
 
 
@@ -317,7 +317,7 @@ describe( 'Link', () => {
 				const viewDocument = editor.editing.view;
 				const viewDocument = editor.editing.view;
 
 
 				setModelData(
 				setModelData(
-					editor.document,
+					editor.model,
 					'<paragraph><$text linkHref="url">f[]oo</$text>bar<$text linkHref="url">b[]az</$text></paragraph>'
 					'<paragraph><$text linkHref="url">f[]oo</$text>bar<$text linkHref="url">b[]az</$text></paragraph>'
 				);
 				);
 
 
@@ -341,7 +341,7 @@ describe( 'Link', () => {
 			it( 'hides the panel – editing a link, then the selection expands upon #render', () => {
 			it( 'hides the panel – editing a link, then the selection expands upon #render', () => {
 				const viewDocument = editor.editing.view;
 				const viewDocument = editor.editing.view;
 
 
-				setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 
 				linkFeature._showPanel();
 				linkFeature._showPanel();
 
 
@@ -594,69 +594,69 @@ describe( 'Link', () => {
 
 
 			beforeEach( () => {
 			beforeEach( () => {
 				observer = editor.editing.view.getObserver( ClickObserver );
 				observer = editor.editing.view.getObserver( ClickObserver );
-				editor.document.schema.allow( { name: '$text', inside: '$root' } );
+				editor.model.schema.allow( { name: '$text', inside: '$root' } );
 
 
 				spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
 				spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
 			} );
 			} );
 
 
 			it( 'should open with not selected formView when collapsed selection is inside link element', () => {
 			it( 'should open with not selected formView when collapsed selection is inside link element', () => {
-				setModelData( editor.document, '<$text linkHref="url">fo[]o</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">fo[]o</$text>' );
 
 
 				observer.fire( 'click', { target: document.body } );
 				observer.fire( 'click', { target: document.body } );
 				sinon.assert.calledWithExactly( spy );
 				sinon.assert.calledWithExactly( spy );
 			} );
 			} );
 
 
 			it( 'should open when selection exclusively encloses a LinkElement (#1)', () => {
 			it( 'should open when selection exclusively encloses a LinkElement (#1)', () => {
-				setModelData( editor.document, '[<$text linkHref="url">foo</$text>]' );
+				setModelData( editor.model, '[<$text linkHref="url">foo</$text>]' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.calledWithExactly( spy );
 				sinon.assert.calledWithExactly( spy );
 			} );
 			} );
 
 
 			it( 'should open when selection exclusively encloses a LinkElement (#2)', () => {
 			it( 'should open when selection exclusively encloses a LinkElement (#2)', () => {
-				setModelData( editor.document, '<$text linkHref="url">[foo]</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">[foo]</$text>' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.calledWithExactly( spy );
 				sinon.assert.calledWithExactly( spy );
 			} );
 			} );
 
 
 			it( 'should not open when selection is not inside link element', () => {
 			it( 'should not open when selection is not inside link element', () => {
-				setModelData( editor.document, '[]' );
+				setModelData( editor.model, '[]' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 				sinon.assert.notCalled( spy );
 			} );
 			} );
 
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#1)', () => {
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#1)', () => {
-				setModelData( editor.document, '<$text linkHref="url">f[o]o</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">f[o]o</$text>' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 				sinon.assert.notCalled( spy );
 			} );
 			} );
 
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#2)', () => {
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#2)', () => {
-				setModelData( editor.document, '<$text linkHref="url">[fo]o</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">[fo]o</$text>' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 				sinon.assert.notCalled( spy );
 			} );
 			} );
 
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#3)', () => {
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#3)', () => {
-				setModelData( editor.document, '<$text linkHref="url">f[oo]</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">f[oo]</$text>' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 				sinon.assert.notCalled( spy );
 			} );
 			} );
 
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#4)', () => {
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#4)', () => {
-				setModelData( editor.document, 'ba[r<$text linkHref="url">foo]</$text>' );
+				setModelData( editor.model, 'ba[r<$text linkHref="url">foo]</$text>' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 				sinon.assert.notCalled( spy );
 			} );
 			} );
 
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#5)', () => {
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#5)', () => {
-				setModelData( editor.document, 'ba[r<$text linkHref="url">foo</$text>]' );
+				setModelData( editor.model, 'ba[r<$text linkHref="url">foo</$text>]' );
 
 
 				observer.fire( 'click', { target: {} } );
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 				sinon.assert.notCalled( spy );

+ 42 - 42
packages/ckeditor5-link/tests/linkcommand.js

@@ -8,22 +8,22 @@ import LinkCommand from '../src/linkcommand';
 import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 
 describe( 'LinkCommand', () => {
 describe( 'LinkCommand', () => {
-	let editor, document, command;
+	let editor, model, command;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return ModelTestEditor.create()
 		return ModelTestEditor.create()
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				document = editor.document;
+				model = editor.model;
 				command = new LinkCommand( editor );
 				command = new LinkCommand( editor );
 
 
 				// Allow text in $root.
 				// Allow text in $root.
-				document.schema.allow( { name: '$text', inside: '$root' } );
+				model.schema.allow( { name: '$text', inside: '$root' } );
 
 
 				// Allow text with `linkHref` attribute in paragraph.
 				// Allow text with `linkHref` attribute in paragraph.
-				document.schema.registerItem( 'p', '$block' );
-				document.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
-				document.schema.allow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
+				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
 			} );
 			} );
 	} );
 	} );
 
 
@@ -36,30 +36,30 @@ describe( 'LinkCommand', () => {
 		// refresh() uses `isAttributeAllowedInSelection` helper which is fully tested in his own test.
 		// refresh() uses `isAttributeAllowedInSelection` helper which is fully tested in his own test.
 
 
 		beforeEach( () => {
 		beforeEach( () => {
-			document.schema.registerItem( 'x', '$block' );
-			document.schema.disallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
+			model.schema.registerItem( 'x', '$block' );
+			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
 		} );
 		} );
 
 
 		describe( 'when selection is collapsed', () => {
 		describe( 'when selection is collapsed', () => {
 			it( 'should be true if characters with the attribute can be placed at caret position', () => {
 			it( 'should be true if characters with the attribute can be placed at caret position', () => {
-				setData( document, '<p>f[]oo</p>' );
+				setData( model, '<p>f[]oo</p>' );
 				expect( command.isEnabled ).to.be.true;
 				expect( command.isEnabled ).to.be.true;
 			} );
 			} );
 
 
 			it( 'should be false if characters with the attribute cannot be placed at caret position', () => {
 			it( 'should be false if characters with the attribute cannot be placed at caret position', () => {
-				setData( document, '<x>fo[]o</x>' );
+				setData( model, '<x>fo[]o</x>' );
 				expect( command.isEnabled ).to.be.false;
 				expect( command.isEnabled ).to.be.false;
 			} );
 			} );
 		} );
 		} );
 
 
 		describe( 'when selection is not collapsed', () => {
 		describe( 'when selection is not collapsed', () => {
 			it( 'should be true if there is at least one node in selection that can have the attribute', () => {
 			it( 'should be true if there is at least one node in selection that can have the attribute', () => {
-				setData( document, '<p>[foo]</p>' );
+				setData( model, '<p>[foo]</p>' );
 				expect( command.isEnabled ).to.be.true;
 				expect( command.isEnabled ).to.be.true;
 			} );
 			} );
 
 
 			it( 'should be false if there are no nodes in selection that can have the attribute', () => {
 			it( 'should be false if there are no nodes in selection that can have the attribute', () => {
-				setData( document, '<x>[foo]</x>' );
+				setData( model, '<x>[foo]</x>' );
 				expect( command.isEnabled ).to.be.false;
 				expect( command.isEnabled ).to.be.false;
 			} );
 			} );
 		} );
 		} );
@@ -68,13 +68,13 @@ describe( 'LinkCommand', () => {
 	describe( 'value', () => {
 	describe( 'value', () => {
 		describe( 'collapsed selection', () => {
 		describe( 'collapsed selection', () => {
 			it( 'should be equal attribute value when selection is placed inside element with `linkHref` attribute', () => {
 			it( 'should be equal attribute value when selection is placed inside element with `linkHref` attribute', () => {
-				setData( document, '<$text linkHref="url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="url">foo[]bar</$text>' );
 
 
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should be undefined when selection is placed inside element without `linkHref` attribute', () => {
 			it( 'should be undefined when selection is placed inside element without `linkHref` attribute', () => {
-				setData( document, '<$text bold="true">foo[]bar</$text>' );
+				setData( model, '<$text bold="true">foo[]bar</$text>' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 			} );
 			} );
@@ -82,13 +82,13 @@ describe( 'LinkCommand', () => {
 
 
 		describe( 'non-collapsed selection', () => {
 		describe( 'non-collapsed selection', () => {
 			it( 'should be equal attribute value when selection contains only elements with `linkHref` attribute', () => {
 			it( 'should be equal attribute value when selection contains only elements with `linkHref` attribute', () => {
-				setData( document, 'fo[<$text linkHref="url">ob</$text>]ar' );
+				setData( model, 'fo[<$text linkHref="url">ob</$text>]ar' );
 
 
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should be undefined when selection contains not only elements with `linkHref` attribute', () => {
 			it( 'should be undefined when selection contains not only elements with `linkHref` attribute', () => {
-				setData( document, 'f[o<$text linkHref="url">ob</$text>]ar' );
+				setData( model, 'f[o<$text linkHref="url">ob</$text>]ar' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 			} );
 			} );
@@ -98,25 +98,25 @@ describe( 'LinkCommand', () => {
 	describe( 'execute()', () => {
 	describe( 'execute()', () => {
 		describe( 'non-collapsed selection', () => {
 		describe( 'non-collapsed selection', () => {
 			it( 'should set `linkHref` attribute to selected text', () => {
 			it( 'should set `linkHref` attribute to selected text', () => {
-				setData( document, 'f[ooba]r' );
+				setData( model, 'f[ooba]r' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
+				expect( getData( model ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should set `linkHref` attribute to selected text when text already has attributes', () => {
 			it( 'should set `linkHref` attribute to selected text when text already has attributes', () => {
-				setData( document, 'f[o<$text bold="true">oba]r</$text>' );
+				setData( model, 'f[o<$text bold="true">oba]r</$text>' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'f[<$text linkHref="url">o</$text>' +
 					'f[<$text linkHref="url">o</$text>' +
 					'<$text bold="true" linkHref="url">oba</$text>]' +
 					'<$text bold="true" linkHref="url">oba</$text>]' +
 					'<$text bold="true">r</$text>'
 					'<$text bold="true">r</$text>'
@@ -124,24 +124,24 @@ describe( 'LinkCommand', () => {
 			} );
 			} );
 
 
 			it( 'should overwrite existing `linkHref` attribute when selected text wraps text with `linkHref` attribute', () => {
 			it( 'should overwrite existing `linkHref` attribute when selected text wraps text with `linkHref` attribute', () => {
-				setData( document, 'f[o<$text linkHref="other url">o</$text>ba]r' );
+				setData( model, 'f[o<$text linkHref="other url">o</$text>ba]r' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
+				expect( getData( model ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should split text and overwrite attribute value when selection is inside text with `linkHref` attribute', () => {
 			it( 'should split text and overwrite attribute value when selection is inside text with `linkHref` attribute', () => {
-				setData( document, 'f<$text linkHref="other url">o[ob]a</$text>r' );
+				setData( model, 'f<$text linkHref="other url">o[ob]a</$text>r' );
 
 
 				expect( command.value ).to.equal( 'other url' );
 				expect( command.value ).to.equal( 'other url' );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'f' +
 					'f' +
 					'<$text linkHref="other url">o</$text>' +
 					'<$text linkHref="other url">o</$text>' +
 					'[<$text linkHref="url">ob</$text>]' +
 					'[<$text linkHref="url">ob</$text>]' +
@@ -154,51 +154,51 @@ describe( 'LinkCommand', () => {
 			it( 'should overwrite `linkHref` attribute of selected text only, ' +
 			it( 'should overwrite `linkHref` attribute of selected text only, ' +
 				'when selection start inside text with `linkHref` attribute',
 				'when selection start inside text with `linkHref` attribute',
 			() => {
 			() => {
-				setData( document, 'f<$text linkHref="other url">o[o</$text>ba]r' );
+				setData( model, 'f<$text linkHref="other url">o[o</$text>ba]r' );
 
 
 				expect( command.value ).to.equal( 'other url' );
 				expect( command.value ).to.equal( 'other url' );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( 'f<$text linkHref="other url">o</$text>[<$text linkHref="url">oba</$text>]r' );
+				expect( getData( model ) ).to.equal( 'f<$text linkHref="other url">o</$text>[<$text linkHref="url">oba</$text>]r' );
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should overwrite `linkHref` attribute of selected text only, when selection end inside text with `linkHref` ' +
 			it( 'should overwrite `linkHref` attribute of selected text only, when selection end inside text with `linkHref` ' +
 				'attribute', () => {
 				'attribute', () => {
-				setData( document, 'f[o<$text linkHref="other url">ob]a</$text>r' );
+				setData( model, 'f[o<$text linkHref="other url">ob]a</$text>r' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">oob</$text>]<$text linkHref="other url">a</$text>r' );
+				expect( getData( model ) ).to.equal( 'f[<$text linkHref="url">oob</$text>]<$text linkHref="other url">a</$text>r' );
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should set `linkHref` attribute to selected text when text is split by $block element', () => {
 			it( 'should set `linkHref` attribute to selected text when text is split by $block element', () => {
-				setData( document, '<p>f[oo</p><p>ba]r</p>' );
+				setData( model, '<p>f[oo</p><p>ba]r</p>' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) )
+				expect( getData( model ) )
 					.to.equal( '<p>f[<$text linkHref="url">oo</$text></p><p><$text linkHref="url">ba</$text>]r</p>' );
 					.to.equal( '<p>f[<$text linkHref="url">oo</$text></p><p><$text linkHref="url">ba</$text>]r</p>' );
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
 
 
 			it( 'should set `linkHref` attribute only to allowed elements and omit disallowed', () => {
 			it( 'should set `linkHref` attribute only to allowed elements and omit disallowed', () => {
 				// Disallow text in img.
 				// Disallow text in img.
-				document.schema.registerItem( 'img', '$inline' );
+				model.schema.registerItem( 'img', '$inline' );
 
 
-				setData( document, '<p>f[oo<img></img>ba]r</p>' );
+				setData( model, '<p>f[oo<img></img>ba]r</p>' );
 
 
 				expect( command.value ).to.be.undefined;
 				expect( command.value ).to.be.undefined;
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) )
+				expect( getData( model ) )
 					.to.equal( '<p>f[<$text linkHref="url">oo</$text><img></img><$text linkHref="url">ba</$text>]r</p>' );
 					.to.equal( '<p>f[<$text linkHref="url">oo</$text><img></img><$text linkHref="url">ba</$text>]r</p>' );
 				expect( command.value ).to.equal( 'url' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 			} );
@@ -206,38 +206,38 @@ describe( 'LinkCommand', () => {
 
 
 		describe( 'collapsed selection', () => {
 		describe( 'collapsed selection', () => {
 			it( 'should insert text with `linkHref` attribute, text data equal to href and select new link', () => {
 			it( 'should insert text with `linkHref` attribute, text data equal to href and select new link', () => {
-				setData( document, 'foo[]bar' );
+				setData( model, 'foo[]bar' );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
+				expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
 			} );
 
 
 			it( 'should insert text with `linkHref` attribute, and selection attributes', () => {
 			it( 'should insert text with `linkHref` attribute, and selection attributes', () => {
-				setData( document, '<$text bold="true">foo[]bar</$text>', {
+				setData( model, '<$text bold="true">foo[]bar</$text>', {
 					selectionAttributes: { bold: true }
 					selectionAttributes: { bold: true }
 				} );
 				} );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( '<$text bold="true">foo[<$text linkHref="url">url</$text>]bar</$text>' );
+				expect( getData( model ) ).to.equal( '<$text bold="true">foo[<$text linkHref="url">url</$text>]bar</$text>' );
 			} );
 			} );
 
 
 			it( 'should update `linkHref` attribute and select whole link when selection is inside text with `linkHref` attribute', () => {
 			it( 'should update `linkHref` attribute and select whole link when selection is inside text with `linkHref` attribute', () => {
-				setData( document, '<$text linkHref="other url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="other url">foo[]bar</$text>' );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( '[<$text linkHref="url">foobar</$text>]' );
+				expect( getData( model ) ).to.equal( '[<$text linkHref="url">foobar</$text>]' );
 			} );
 			} );
 
 
 			it( 'should not insert text with `linkHref` attribute when is not allowed in parent', () => {
 			it( 'should not insert text with `linkHref` attribute when is not allowed in parent', () => {
-				document.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
-				setData( document, '<p>foo[]bar</p>' );
+				model.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
+				setData( model, '<p>foo[]bar</p>' );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );
 
 
-				expect( getData( document ) ).to.equal( '<p>foo[]bar</p>' );
+				expect( getData( model ) ).to.equal( '<p>foo[]bar</p>' );
 			} );
 			} );
 		} );
 		} );
 	} );
 	} );

+ 13 - 14
packages/ckeditor5-link/tests/linkengine.js

@@ -16,7 +16,7 @@ import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils
 import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
 import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
 
 
 describe( 'LinkEngine', () => {
 describe( 'LinkEngine', () => {
-	let editor, doc;
+	let editor, model;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -25,8 +25,7 @@ describe( 'LinkEngine', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-
-				doc = editor.document;
+				model = editor.model;
 			} );
 			} );
 	} );
 	} );
 
 
@@ -35,9 +34,9 @@ describe( 'LinkEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( doc.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$root' } ) ).to.be.false;
-		expect( doc.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$block' } ) ).to.be.true;
-		expect( doc.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {
@@ -58,7 +57,7 @@ describe( 'LinkEngine', () => {
 		it( 'should convert `<a href="url">` to `linkHref="url"` attribute', () => {
 		it( 'should convert `<a href="url">` to `linkHref="url"` attribute', () => {
 			editor.setData( '<p><a href="url">foo</a>bar</p>' );
 			editor.setData( '<p><a href="url">foo</a>bar</p>' );
 
 
-			expect( getModelData( doc, { withoutSelection: true } ) )
+			expect( getModelData( model, { withoutSelection: true } ) )
 				.to.equal( '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 				.to.equal( '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 
 			expect( editor.getData() ).to.equal( '<p><a href="url">foo</a>bar</p>' );
 			expect( editor.getData() ).to.equal( '<p><a href="url">foo</a>bar</p>' );
@@ -70,7 +69,7 @@ describe( 'LinkEngine', () => {
 
 
 			editor.setData( '<a href="url">foo</a>bar' );
 			editor.setData( '<a href="url">foo</a>bar' );
 
 
-			expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
 
 
 			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
 			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
 		} );
 		} );
@@ -79,7 +78,7 @@ describe( 'LinkEngine', () => {
 		it( 'should not pick up `<a name="foo">`', () => {
 		it( 'should not pick up `<a name="foo">`', () => {
 			editor.setData( '<p><a name="foo">foo</a>bar</p>' );
 			editor.setData( '<p><a name="foo">foo</a>bar</p>' );
 
 
-			expect( getModelData( doc, { withoutSelection: true } ) )
+			expect( getModelData( model, { withoutSelection: true } ) )
 				.to.equal( '<paragraph>foobar</paragraph>' );
 				.to.equal( '<paragraph>foobar</paragraph>' );
 		} );
 		} );
 
 
@@ -87,7 +86,7 @@ describe( 'LinkEngine', () => {
 		it( 'should pick up `<a href="">`', () => {
 		it( 'should pick up `<a href="">`', () => {
 			editor.setData( '<p><a href="">foo</a>bar</p>' );
 			editor.setData( '<p><a href="">foo</a>bar</p>' );
 
 
-			expect( getModelData( doc, { withoutSelection: true } ) )
+			expect( getModelData( model, { withoutSelection: true } ) )
 				.to.equal( '<paragraph><$text linkHref="">foo</$text>bar</paragraph>' );
 				.to.equal( '<paragraph><$text linkHref="">foo</$text>bar</paragraph>' );
 
 
 			expect( editor.getData() ).to.equal( '<p><a href="">foo</a>bar</p>' );
 			expect( editor.getData() ).to.equal( '<p><a href="">foo</a>bar</p>' );
@@ -96,26 +95,26 @@ describe( 'LinkEngine', () => {
 
 
 	describe( 'editing pipeline conversion', () => {
 	describe( 'editing pipeline conversion', () => {
 		it( 'should convert attribute', () => {
 		it( 'should convert attribute', () => {
-			setModelData( doc, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
+			setModelData( model, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><a href="url">foo</a>bar</p>' );
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><a href="url">foo</a>bar</p>' );
 		} );
 		} );
 
 
 		it( 'should convert to `LinkElement` instance', () => {
 		it( 'should convert to `LinkElement` instance', () => {
-			setModelData( doc, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
+			setModelData( model, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 
 			expect( editor.editing.view.getRoot().getChild( 0 ).getChild( 0 ) ).to.be.instanceof( LinkElement );
 			expect( editor.editing.view.getRoot().getChild( 0 ).getChild( 0 ) ).to.be.instanceof( LinkElement );
 		} );
 		} );
 
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/121
 		// https://github.com/ckeditor/ckeditor5-link/issues/121
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
-			editor.document.schema.allow( { name: '$inline', attributes: [ 'foo' ], inside: '$block' } );
+			model.schema.allow( { name: '$inline', attributes: [ 'foo' ], inside: '$block' } );
 
 
 			buildModelConverter().for( editor.data.modelToView )
 			buildModelConverter().for( editor.data.modelToView )
 				.fromAttribute( 'foo' )
 				.fromAttribute( 'foo' )
 				.toElement( 'f' );
 				.toElement( 'f' );
 
 
-			setModelData( doc,
+			setModelData( model,
 				'<paragraph>' +
 				'<paragraph>' +
 					'<$text linkHref="url">a</$text><$text foo="true" linkHref="url">b</$text><$text linkHref="url">c</$text>' +
 					'<$text linkHref="url">a</$text><$text foo="true" linkHref="url">b</$text><$text linkHref="url">c</$text>' +
 				'</paragraph>' );
 				'</paragraph>' );

+ 9 - 13
packages/ckeditor5-link/tests/manual/tickets/113/1.js

@@ -8,8 +8,6 @@
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 
 
-import Element from '@ckeditor/ckeditor5-engine/src/model/element';
-import Text from '@ckeditor/ckeditor5-engine/src/model/text';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 
@@ -52,18 +50,17 @@ function wait( delay ) {
 }
 }
 
 
 function startExternalInsert( editor ) {
 function startExternalInsert( editor ) {
-	const document = editor.document;
-	const bath = document.batch( 'transparent' );
+	const model = editor.model;
 
 
 	function type( path, text ) {
 	function type( path, text ) {
 		return new Promise( resolve => {
 		return new Promise( resolve => {
-			let position = new Position( document.getRoot(), path );
+			let position = new Position( model.document.getRoot(), path );
 			let index = 0;
 			let index = 0;
 
 
 			function typing() {
 			function typing() {
 				wait( 40 ).then( () => {
 				wait( 40 ).then( () => {
-					document.enqueueChanges( () => {
-						bath.insert( position, new Text( text[ index ] ) );
+					model.enqueueChange( 'transparent', writer => {
+						writer.insertText( text[ index ], position );
 						position = position.getShiftedBy( 1 );
 						position = position.getShiftedBy( 1 );
 
 
 						const nextLetter = text[ ++index ];
 						const nextLetter = text[ ++index ];
@@ -84,8 +81,8 @@ function startExternalInsert( editor ) {
 
 
 	function insertNewLine( path ) {
 	function insertNewLine( path ) {
 		return wait( 200 ).then( () => {
 		return wait( 200 ).then( () => {
-			document.enqueueChanges( () => {
-				bath.insert( new Position( document.getRoot(), path ), new Element( 'paragraph' ) );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertElement( 'paragraph', new Position( model.document.getRoot(), path ) );
 			} );
 			} );
 
 
 			return Promise.resolve();
 			return Promise.resolve();
@@ -105,12 +102,11 @@ function startExternalInsert( editor ) {
 }
 }
 
 
 function startExternalDelete( editor ) {
 function startExternalDelete( editor ) {
-	const document = editor.document;
-	const bath = document.batch( 'transparent' );
+	const model = editor.model;
 
 
 	wait( 3000 ).then( () => {
 	wait( 3000 ).then( () => {
-		document.enqueueChanges( () => {
-			bath.remove( Range.createFromPositionAndShift( new Position( document.getRoot(), [ 1 ] ), 1 ) );
+		model.enqueueChange( 'transparent', writer => {
+			writer.remove( Range.createFromPositionAndShift( new Position( model.document.getRoot(), [ 1 ] ), 1 ) );
 		} );
 		} );
 	} );
 	} );
 }
 }

+ 33 - 32
packages/ckeditor5-link/tests/unlinkcommand.js

@@ -11,21 +11,22 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'UnlinkCommand', () => {
 describe( 'UnlinkCommand', () => {
-	let editor, document, command;
+	let editor, model, document, command;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return ModelTestEditor.create()
 		return ModelTestEditor.create()
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				document = editor.document;
+				model = editor.model;
+				document = model.document;
 				command = new UnlinkCommand( editor );
 				command = new UnlinkCommand( editor );
 
 
 				// Allow text in $root.
 				// Allow text in $root.
-				document.schema.allow( { name: '$text', inside: '$root' } );
+				model.schema.allow( { name: '$text', inside: '$root' } );
 
 
 				// Allow text with `linkHref` attribute in paragraph.
 				// Allow text with `linkHref` attribute in paragraph.
-				document.schema.registerItem( 'p', '$block' );
-				document.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
 			} );
 			} );
 	} );
 	} );
 
 
@@ -35,7 +36,7 @@ describe( 'UnlinkCommand', () => {
 
 
 	describe( 'isEnabled', () => {
 	describe( 'isEnabled', () => {
 		it( 'should be true when selection has `linkHref` attribute', () => {
 		it( 'should be true when selection has `linkHref` attribute', () => {
-			document.enqueueChanges( () => {
+			model.change( () => {
 				document.selection.setAttribute( 'linkHref', 'value' );
 				document.selection.setAttribute( 'linkHref', 'value' );
 			} );
 			} );
 
 
@@ -43,7 +44,7 @@ describe( 'UnlinkCommand', () => {
 		} );
 		} );
 
 
 		it( 'should be false when selection doesn\'t have `linkHref` attribute', () => {
 		it( 'should be false when selection doesn\'t have `linkHref` attribute', () => {
-			document.enqueueChanges( () => {
+			model.change( () => {
 				document.selection.removeAttribute( 'linkHref' );
 				document.selection.removeAttribute( 'linkHref' );
 			} );
 			} );
 
 
@@ -54,20 +55,20 @@ describe( 'UnlinkCommand', () => {
 	describe( 'execute()', () => {
 	describe( 'execute()', () => {
 		describe( 'non-collapsed selection', () => {
 		describe( 'non-collapsed selection', () => {
 			it( 'should remove `linkHref` attribute from selected text', () => {
 			it( 'should remove `linkHref` attribute from selected text', () => {
-				setData( document, '<$text linkHref="url">f[ooba]r</$text>' );
+				setData( model, '<$text linkHref="url">f[ooba]r</$text>' );
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal( '<$text linkHref="url">f</$text>[ooba]<$text linkHref="url">r</$text>' );
+				expect( getData( model ) ).to.equal( '<$text linkHref="url">f</$text>[ooba]<$text linkHref="url">r</$text>' );
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selected text and do not modified other attributes', () => {
 			it( 'should remove `linkHref` attribute from selected text and do not modified other attributes', () => {
-				setData( document, '<$text bold="true" linkHref="url">f[ooba]r</$text>' );
+				setData( model, '<$text bold="true" linkHref="url">f[ooba]r</$text>' );
 
 
 				command.execute();
 				command.execute();
 
 
 				const assertAll = () => {
 				const assertAll = () => {
-					expect( getData( document ) ).to.equal(
+					expect( getData( model ) ).to.equal(
 						'<$text bold="true" linkHref="url">f</$text>' +
 						'<$text bold="true" linkHref="url">f</$text>' +
 						'[<$text bold="true">ooba</$text>]' +
 						'[<$text bold="true">ooba</$text>]' +
 						'<$text bold="true" linkHref="url">r</$text>'
 						'<$text bold="true" linkHref="url">r</$text>'
@@ -75,7 +76,7 @@ describe( 'UnlinkCommand', () => {
 				};
 				};
 
 
 				const assertEdge = () => {
 				const assertEdge = () => {
-					expect( getData( document ) ).to.equal(
+					expect( getData( model ) ).to.equal(
 						'<$text bold="true" linkHref="url">f</$text>' +
 						'<$text bold="true" linkHref="url">f</$text>' +
 						'[<$text bold="true">ooba]<$text linkHref="url">r</$text></$text>'
 						'[<$text bold="true">ooba]<$text linkHref="url">r</$text></$text>'
 					);
 					);
@@ -85,15 +86,15 @@ describe( 'UnlinkCommand', () => {
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selected text when attributes have different value', () => {
 			it( 'should remove `linkHref` attribute from selected text when attributes have different value', () => {
-				setData( document, '[<$text linkHref="url">foo</$text><$text linkHref="other url">bar</$text>]' );
+				setData( model, '[<$text linkHref="url">foo</$text><$text linkHref="other url">bar</$text>]' );
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal( '[foobar]' );
+				expect( getData( model ) ).to.equal( '[foobar]' );
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selection', () => {
 			it( 'should remove `linkHref` attribute from selection', () => {
-				setData( document, '<$text linkHref="url">f[ooba]r</$text>' );
+				setData( model, '<$text linkHref="url">f[ooba]r</$text>' );
 
 
 				command.execute();
 				command.execute();
 
 
@@ -103,17 +104,17 @@ describe( 'UnlinkCommand', () => {
 
 
 		describe( 'collapsed selection', () => {
 		describe( 'collapsed selection', () => {
 			it( 'should remove `linkHref` attribute from selection siblings with the same attribute value', () => {
 			it( 'should remove `linkHref` attribute from selection siblings with the same attribute value', () => {
-				setData( document, '<$text linkHref="url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="url">foo[]bar</$text>' );
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal( 'foo[]bar' );
+				expect( getData( model ) ).to.equal( 'foo[]bar' );
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selection siblings with the same attribute value and do not modify ' +
 			it( 'should remove `linkHref` attribute from selection siblings with the same attribute value and do not modify ' +
 				'other attributes', () => {
 				'other attributes', () => {
 				setData(
 				setData(
-					document,
+					model,
 					'<$text linkHref="other url">fo</$text>' +
 					'<$text linkHref="other url">fo</$text>' +
 					'<$text linkHref="url">o[]b</$text>' +
 					'<$text linkHref="url">o[]b</$text>' +
 					'<$text linkHref="other url">ar</$text>'
 					'<$text linkHref="other url">ar</$text>'
@@ -121,7 +122,7 @@ describe( 'UnlinkCommand', () => {
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'<$text linkHref="other url">fo</$text>' +
 					'<$text linkHref="other url">fo</$text>' +
 					'o[]b' +
 					'o[]b' +
 					'<$text linkHref="other url">ar</$text>'
 					'<$text linkHref="other url">ar</$text>'
@@ -131,7 +132,7 @@ describe( 'UnlinkCommand', () => {
 			it( 'should do nothing with nodes with the same `linkHref` value when there is a node with different value `linkHref` ' +
 			it( 'should do nothing with nodes with the same `linkHref` value when there is a node with different value `linkHref` ' +
 				'attribute between', () => {
 				'attribute between', () => {
 				setData(
 				setData(
-					document,
+					model,
 					'<$text linkHref="same url">f</$text>' +
 					'<$text linkHref="same url">f</$text>' +
 					'<$text linkHref="other url">o</$text>' +
 					'<$text linkHref="other url">o</$text>' +
 					'<$text linkHref="same url">o[]b</$text>' +
 					'<$text linkHref="same url">o[]b</$text>' +
@@ -141,7 +142,7 @@ describe( 'UnlinkCommand', () => {
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) )
+				expect( getData( model ) )
 					.to.equal(
 					.to.equal(
 						'<$text linkHref="same url">f</$text>' +
 						'<$text linkHref="same url">f</$text>' +
 						'<$text linkHref="other url">o</$text>' +
 						'<$text linkHref="other url">o</$text>' +
@@ -155,7 +156,7 @@ describe( 'UnlinkCommand', () => {
 				'and do nothing with other attributes',
 				'and do nothing with other attributes',
 			() => {
 			() => {
 				setData(
 				setData(
-					document,
+					model,
 					'<$text linkHref="url">f</$text>' +
 					'<$text linkHref="url">f</$text>' +
 					'<$text bold="true" linkHref="url">o</$text>' +
 					'<$text bold="true" linkHref="url">o</$text>' +
 					'<$text linkHref="url">o[]b</$text>' +
 					'<$text linkHref="url">o[]b</$text>' +
@@ -165,7 +166,7 @@ describe( 'UnlinkCommand', () => {
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'f' +
 					'f' +
 					'<$text bold="true">o</$text>' +
 					'<$text bold="true">o</$text>' +
 					'o[]b' +
 					'o[]b' +
@@ -176,7 +177,7 @@ describe( 'UnlinkCommand', () => {
 
 
 			it( 'should remove `linkHref` attribute from selection siblings only in the same parent as selection parent', () => {
 			it( 'should remove `linkHref` attribute from selection siblings only in the same parent as selection parent', () => {
 				setData(
 				setData(
-					document,
+					model,
 					'<p><$text linkHref="url">bar</$text></p>' +
 					'<p><$text linkHref="url">bar</$text></p>' +
 					'<p><$text linkHref="url">fo[]o</$text></p>' +
 					'<p><$text linkHref="url">fo[]o</$text></p>' +
 					'<p><$text linkHref="url">bar</$text></p>'
 					'<p><$text linkHref="url">bar</$text></p>'
@@ -184,7 +185,7 @@ describe( 'UnlinkCommand', () => {
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'<p><$text linkHref="url">bar</$text></p>' +
 					'<p><$text linkHref="url">bar</$text></p>' +
 					'<p>fo[]o</p>' +
 					'<p>fo[]o</p>' +
 					'<p><$text linkHref="url">bar</$text></p>'
 					'<p><$text linkHref="url">bar</$text></p>'
@@ -192,33 +193,33 @@ describe( 'UnlinkCommand', () => {
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selection siblings when selection is at the end of link', () => {
 			it( 'should remove `linkHref` attribute from selection siblings when selection is at the end of link', () => {
-				setData( document, '<$text linkHref="url">foobar</$text>[]' );
+				setData( model, '<$text linkHref="url">foobar</$text>[]' );
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal( 'foobar[]' );
+				expect( getData( model ) ).to.equal( 'foobar[]' );
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selection siblings when selection is at the beginning of link', () => {
 			it( 'should remove `linkHref` attribute from selection siblings when selection is at the beginning of link', () => {
-				setData( document, '[]<$text linkHref="url">foobar</$text>' );
+				setData( model, '[]<$text linkHref="url">foobar</$text>' );
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal( '[]foobar' );
+				expect( getData( model ) ).to.equal( '[]foobar' );
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selection siblings on the left side when selection is between two elements with ' +
 			it( 'should remove `linkHref` attribute from selection siblings on the left side when selection is between two elements with ' +
 				'different `linkHref` attributes',
 				'different `linkHref` attributes',
 			() => {
 			() => {
-				setData( document, '<$text linkHref="url">foo</$text>[]<$text linkHref="other url">bar</$text>' );
+				setData( model, '<$text linkHref="url">foo</$text>[]<$text linkHref="other url">bar</$text>' );
 
 
 				command.execute();
 				command.execute();
 
 
-				expect( getData( document ) ).to.equal( 'foo[]<$text linkHref="other url">bar</$text>' );
+				expect( getData( model ) ).to.equal( 'foo[]<$text linkHref="other url">bar</$text>' );
 			} );
 			} );
 
 
 			it( 'should remove `linkHref` attribute from selection', () => {
 			it( 'should remove `linkHref` attribute from selection', () => {
-				setData( document, '<$text linkHref="url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="url">foo[]bar</$text>' );
 
 
 				command.execute();
 				command.execute();