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

Merge branch 'master' into t/340

Piotrek Koszuliński 8 лет назад
Родитель
Сommit
d79a00444f

+ 1 - 1
packages/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar.js

@@ -128,7 +128,7 @@ export default class ContextualToolbar extends Plugin {
 	 * @private
 	 * @private
 	 */
 	 */
 	_handleSelectionChange() {
 	_handleSelectionChange() {
-		const selection = this.editor.document.selection;
+		const selection = this.editor.model.document.selection;
 		const editingView = this.editor.editing.view;
 		const editingView = this.editor.editing.view;
 
 
 		this.listenTo( selection, 'change:range', ( evt, data ) => {
 		this.listenTo( selection, 'change:range', ( evt, data ) => {

+ 9 - 13
packages/ckeditor5-ui/tests/manual/contextualballoon/externalchanges.js

@@ -9,8 +9,6 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'
 import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
 import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
 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';
 
 
@@ -55,18 +53,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 ];
@@ -87,8 +84,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();
@@ -108,12 +105,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 ) );
 		} );
 		} );
 	} );
 	} );
 }
 }

+ 2 - 2
packages/ckeditor5-ui/tests/manual/contextualtoolbar/contextualtoolbar.js

@@ -22,8 +22,8 @@ ClassicEditor
 		const contextualToolbar = editor.plugins.get( 'ContextualToolbar' );
 		const contextualToolbar = editor.plugins.get( 'ContextualToolbar' );
 
 
 		contextualToolbar.on( 'show', evt => {
 		contextualToolbar.on( 'show', evt => {
-			const selectionRange = editor.document.selection.getFirstRange();
-			const blockRange = Range.createOn( editor.document.getRoot().getChild( 0 ) );
+			const selectionRange = editor.model.document.selection.getFirstRange();
+			const blockRange = Range.createOn( editor.model.document.getRoot().getChild( 0 ) );
 
 
 			if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
 			if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
 				evt.stop();
 				evt.stop();

+ 9 - 13
packages/ckeditor5-ui/tests/manual/tickets/198/1.js

@@ -9,8 +9,6 @@ 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 ContextualToolbar from '../../../../src/toolbar/contextual/contextualtoolbar';
 import ContextualToolbar from '../../../../src/toolbar/contextual/contextualtoolbar';
 
 
-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';
 
 
@@ -55,18 +53,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 ];
@@ -87,8 +84,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();
@@ -108,12 +105,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 ) );
 		} );
 		} );
 	} );
 	} );
 }
 }

+ 10 - 10
packages/ckeditor5-ui/tests/panel/balloon/contextualballoon.js

@@ -74,16 +74,16 @@ describe( 'ContextualBalloon', () => {
 		} );
 		} );
 
 
 		describe( 'positionLimiter', () => {
 		describe( 'positionLimiter', () => {
-			let doc, viewDocument, root;
+			let model, viewDocument, root;
 
 
 			beforeEach( () => {
 			beforeEach( () => {
-				doc = editor.document;
+				model = editor.model;
 				viewDocument = editor.editing.view;
 				viewDocument = editor.editing.view;
 				root = viewDocument.getRoot();
 				root = viewDocument.getRoot();
 			} );
 			} );
 
 
 			it( 'obtains the root of the selection', () => {
 			it( 'obtains the root of the selection', () => {
-				setModelData( doc, '<paragraph>[]bar</paragraph>' );
+				setModelData( model, '<paragraph>[]bar</paragraph>' );
 
 
 				expect( balloon.positionLimiter() ).to.equal( viewDocument.domConverter.mapViewToDom( root ) );
 				expect( balloon.positionLimiter() ).to.equal( viewDocument.domConverter.mapViewToDom( root ) );
 			} );
 			} );
@@ -95,14 +95,14 @@ describe( 'ContextualBalloon', () => {
 			} );
 			} );
 
 
 			it( 'obtains the farthest root of the selection (nested editable)', () => {
 			it( 'obtains the farthest root of the selection (nested editable)', () => {
-				doc.schema.registerItem( 'widget' );
-				doc.schema.registerItem( 'nestededitable' );
+				model.schema.registerItem( 'widget' );
+				model.schema.registerItem( 'nestededitable' );
 
 
-				doc.schema.objects.add( 'widget' );
+				model.schema.objects.add( 'widget' );
 
 
-				doc.schema.allow( { name: 'widget', inside: '$root' } );
-				doc.schema.allow( { name: 'nestededitable', inside: 'widget' } );
-				doc.schema.allow( { name: '$inline', inside: 'nestededitable' } );
+				model.schema.allow( { name: 'widget', inside: '$root' } );
+				model.schema.allow( { name: 'nestededitable', inside: 'widget' } );
+				model.schema.allow( { name: '$inline', inside: 'nestededitable' } );
 
 
 				buildModelConverter().for( editor.data.modelToView, editor.editing.modelToView )
 				buildModelConverter().for( editor.data.modelToView, editor.editing.modelToView )
 					.fromElement( 'widget' )
 					.fromElement( 'widget' )
@@ -112,7 +112,7 @@ describe( 'ContextualBalloon', () => {
 					.fromElement( 'nestededitable' )
 					.fromElement( 'nestededitable' )
 					.toElement( () => new ViewEditableElement( 'figcaption', { contenteditable: 'true' } ) );
 					.toElement( () => new ViewEditableElement( 'figcaption', { contenteditable: 'true' } ) );
 
 
-				setModelData( doc, '<widget><nestededitable>[]foo</nestededitable></widget>' );
+				setModelData( model, '<widget><nestededitable>[]foo</nestededitable></widget>' );
 
 
 				expect( balloon.positionLimiter() ).to.equal( viewDocument.domConverter.mapViewToDom( root ) );
 				expect( balloon.positionLimiter() ).to.equal( viewDocument.domConverter.mapViewToDom( root ) );
 			} );
 			} );

+ 39 - 37
packages/ckeditor5-ui/tests/toolbar/contextual/contextualtoolbar.js

@@ -18,7 +18,7 @@ import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
 /* global document, setTimeout, window */
 /* global document, setTimeout, window */
 
 
 describe( 'ContextualToolbar', () => {
 describe( 'ContextualToolbar', () => {
-	let sandbox, editor, contextualToolbar, balloon, editorElement;
+	let sandbox, editor, model, selection, editingView, contextualToolbar, balloon, editorElement;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		sandbox = sinon.sandbox.create();
 		sandbox = sinon.sandbox.create();
@@ -32,19 +32,22 @@ describe( 'ContextualToolbar', () => {
 				contextualToolbar: [ 'bold', 'italic' ]
 				contextualToolbar: [ 'bold', 'italic' ]
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
-				newEditor.editing.view.attachDomRoot( editorElement );
-
 				editor = newEditor;
 				editor = newEditor;
+				model = editor.model;
+				editingView = editor.editing.view;
+				selection = model.document.selection;
 				contextualToolbar = editor.plugins.get( ContextualToolbar );
 				contextualToolbar = editor.plugins.get( ContextualToolbar );
 				balloon = editor.plugins.get( ContextualBalloon );
 				balloon = editor.plugins.get( ContextualBalloon );
 
 
+				editingView.attachDomRoot( editorElement );
+
 				// There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.
 				// There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.
 				sandbox.stub( balloon.view, 'attachTo' ).returns( {} );
 				sandbox.stub( balloon.view, 'attachTo' ).returns( {} );
 				sandbox.stub( balloon.view, 'pin' ).returns( {} );
 				sandbox.stub( balloon.view, 'pin' ).returns( {} );
 
 
 				// Focus the engine.
 				// Focus the engine.
-				editor.editing.view.isFocused = true;
-				editor.editing.view.getDomRoot().focus();
+				editingView.isFocused = true;
+				editingView.getDomRoot().focus();
 
 
 				// Remove all selection ranges from DOM before testing.
 				// Remove all selection ranges from DOM before testing.
 				window.getSelection().removeAllRanges();
 				window.getSelection().removeAllRanges();
@@ -102,10 +105,10 @@ describe( 'ContextualToolbar', () => {
 		// and sinon is not able to override it.
 		// and sinon is not able to override it.
 
 
 		const spy = sandbox.spy();
 		const spy = sandbox.spy();
-		setData( editor.document, '<paragraph>[bar]</paragraph>' );
+		setData( model, '<paragraph>[bar]</paragraph>' );
 		contextualToolbar.on( '_selectionChangeDebounced', spy );
 		contextualToolbar.on( '_selectionChangeDebounced', spy );
 
 
-		editor.document.selection.fire( 'change:range', {} );
+		selection.fire( 'change:range', {} );
 
 
 		// Not yet.
 		// Not yet.
 		sinon.assert.notCalled( spy );
 		sinon.assert.notCalled( spy );
@@ -116,7 +119,7 @@ describe( 'ContextualToolbar', () => {
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
 
 
 			// Fire event one more time.
 			// Fire event one more time.
-			editor.document.selection.fire( 'change:range', {} );
+			selection.fire( 'change:range', {} );
 
 
 			// Another 100 ms waiting.
 			// Another 100 ms waiting.
 			setTimeout( () => {
 			setTimeout( () => {
@@ -167,11 +170,11 @@ describe( 'ContextualToolbar', () => {
 			] );
 			] );
 
 
 			balloonAddSpy = sandbox.spy( balloon, 'add' );
 			balloonAddSpy = sandbox.spy( balloon, 'add' );
-			editor.editing.view.isFocused = true;
+			editingView.isFocused = true;
 		} );
 		} );
 
 
 		it( 'should add #toolbarView to the #_balloon and attach the #_balloon to the selection for the forward selection', () => {
 		it( 'should add #toolbarView to the #_balloon and attach the #_balloon to the selection for the forward selection', () => {
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			const defaultPositions = BalloonPanelView.defaultPositions;
 			const defaultPositions = BalloonPanelView.defaultPositions;
 
 
@@ -199,7 +202,7 @@ describe( 'ContextualToolbar', () => {
 		// https://github.com/ckeditor/ckeditor5-ui/issues/308
 		// https://github.com/ckeditor/ckeditor5-ui/issues/308
 		it( 'should ignore the zero-width orphan rect if there another one preceding it for the forward selection', () => {
 		it( 'should ignore the zero-width orphan rect if there another one preceding it for the forward selection', () => {
 			// Restore previous stubSelectionRects() call.
 			// Restore previous stubSelectionRects() call.
-			editor.editing.view.domConverter.viewRangeToDom.restore();
+			editingView.domConverter.viewRangeToDom.restore();
 
 
 			// Simulate an "orphan" rect preceded by a "correct" one.
 			// Simulate an "orphan" rect preceded by a "correct" one.
 			stubSelectionRects( [
 			stubSelectionRects( [
@@ -207,14 +210,14 @@ describe( 'ContextualToolbar', () => {
 				{ width: 0 }
 				{ width: 0 }
 			] );
 			] );
 
 
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			expect( balloonAddSpy.firstCall.args[ 0 ].position.target() ).to.deep.equal( forwardSelectionRect );
 			expect( balloonAddSpy.firstCall.args[ 0 ].position.target() ).to.deep.equal( forwardSelectionRect );
 		} );
 		} );
 
 
 		it( 'should add #toolbarView to the #_balloon and attach the #_balloon to the selection for the backward selection', () => {
 		it( 'should add #toolbarView to the #_balloon and attach the #_balloon to the selection for the backward selection', () => {
-			setData( editor.document, '<paragraph>b[a]r</paragraph>', { lastRangeBackward: true } );
+			setData( model, '<paragraph>b[a]r</paragraph>', { lastRangeBackward: true } );
 
 
 			const defaultPositions = BalloonPanelView.defaultPositions;
 			const defaultPositions = BalloonPanelView.defaultPositions;
 
 
@@ -240,21 +243,21 @@ describe( 'ContextualToolbar', () => {
 		} );
 		} );
 
 
 		it( 'should update balloon position on ViewDocument#render event while balloon is added to the #_balloon', () => {
 		it( 'should update balloon position on ViewDocument#render event while balloon is added to the #_balloon', () => {
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			const spy = sandbox.spy( balloon, 'updatePosition' );
 			const spy = sandbox.spy( balloon, 'updatePosition' );
 
 
-			editor.editing.view.fire( 'render' );
+			editingView.fire( 'render' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
 
 
-			editor.editing.view.fire( 'render' );
+			editingView.fire( 'render' );
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
 		} );
 		} );
 
 
 		it( 'should not add #toolbarView to the #_balloon more than once', () => {
 		it( 'should not add #toolbarView to the #_balloon more than once', () => {
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			contextualToolbar.show();
 			contextualToolbar.show();
@@ -265,7 +268,7 @@ describe( 'ContextualToolbar', () => {
 			Array.from( contextualToolbar.toolbarView.items ).forEach( item => {
 			Array.from( contextualToolbar.toolbarView.items ).forEach( item => {
 				item.isEnabled = false;
 				item.isEnabled = false;
 			} );
 			} );
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			sinon.assert.notCalled( balloonAddSpy );
 			sinon.assert.notCalled( balloonAddSpy );
@@ -278,7 +281,7 @@ describe( 'ContextualToolbar', () => {
 
 
 			delete contextualToolbar.toolbarView.items.get( 0 ).isEnabled;
 			delete contextualToolbar.toolbarView.items.get( 0 ).isEnabled;
 
 
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			sinon.assert.calledOnce( balloonAddSpy );
 			sinon.assert.calledOnce( balloonAddSpy );
@@ -292,23 +295,23 @@ describe( 'ContextualToolbar', () => {
 			} );
 			} );
 
 
 			it( 'should not be called when the editor is not focused', () => {
 			it( 'should not be called when the editor is not focused', () => {
-				setData( editor.document, '<paragraph>b[a]r</paragraph>' );
-				editor.editing.view.isFocused = false;
+				setData( model, '<paragraph>b[a]r</paragraph>' );
+				editingView.isFocused = false;
 
 
 				contextualToolbar.fire( '_selectionChangeDebounced' );
 				contextualToolbar.fire( '_selectionChangeDebounced' );
 				sinon.assert.notCalled( showSpy );
 				sinon.assert.notCalled( showSpy );
 			} );
 			} );
 
 
 			it( 'should not be called when the selection is collapsed', () => {
 			it( 'should not be called when the selection is collapsed', () => {
-				setData( editor.document, '<paragraph>b[]ar</paragraph>' );
+				setData( model, '<paragraph>b[]ar</paragraph>' );
 
 
 				contextualToolbar.fire( '_selectionChangeDebounced' );
 				contextualToolbar.fire( '_selectionChangeDebounced' );
 				sinon.assert.notCalled( showSpy );
 				sinon.assert.notCalled( showSpy );
 			} );
 			} );
 
 
 			it( 'should be called when the selection is not collapsed and editor is focused', () => {
 			it( 'should be called when the selection is not collapsed and editor is focused', () => {
-				setData( editor.document, '<paragraph>b[a]r</paragraph>' );
-				editor.editing.view.isFocused = true;
+				setData( model, '<paragraph>b[a]r</paragraph>' );
+				editingView.isFocused = true;
 
 
 				contextualToolbar.fire( '_selectionChangeDebounced' );
 				contextualToolbar.fire( '_selectionChangeDebounced' );
 				sinon.assert.calledOnce( showSpy );
 				sinon.assert.calledOnce( showSpy );
@@ -321,11 +324,11 @@ describe( 'ContextualToolbar', () => {
 
 
 		beforeEach( () => {
 		beforeEach( () => {
 			removeBalloonSpy = sandbox.stub( balloon, 'remove' ).returns( {} );
 			removeBalloonSpy = sandbox.stub( balloon, 'remove' ).returns( {} );
-			editor.editing.view.isFocused = true;
+			editingView.isFocused = true;
 		} );
 		} );
 
 
 		it( 'should remove #toolbarView from the #_balloon', () => {
 		it( 'should remove #toolbarView from the #_balloon', () => {
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 
 
@@ -334,14 +337,14 @@ describe( 'ContextualToolbar', () => {
 		} );
 		} );
 
 
 		it( 'should stop update balloon position on ViewDocument#render event', () => {
 		it( 'should stop update balloon position on ViewDocument#render event', () => {
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			const spy = sandbox.spy( balloon, 'updatePosition' );
 			const spy = sandbox.spy( balloon, 'updatePosition' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			contextualToolbar.hide();
 			contextualToolbar.hide();
 
 
-			editor.editing.view.fire( 'render' );
+			editingView.fire( 'render' );
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
 		} );
 		} );
 
 
@@ -365,7 +368,7 @@ describe( 'ContextualToolbar', () => {
 
 
 			contextualToolbar.on( '_selectionChangeDebounced', spy );
 			contextualToolbar.on( '_selectionChangeDebounced', spy );
 
 
-			editor.document.selection.fire( 'change:range', { directChange: true } );
+			selection.fire( 'change:range', { directChange: true } );
 
 
 			contextualToolbar.destroy();
 			contextualToolbar.destroy();
 
 
@@ -380,7 +383,7 @@ describe( 'ContextualToolbar', () => {
 		let showPanelSpy, hidePanelSpy;
 		let showPanelSpy, hidePanelSpy;
 
 
 		beforeEach( () => {
 		beforeEach( () => {
-			setData( editor.document, '<paragraph>[bar]</paragraph>' );
+			setData( model, '<paragraph>[bar]</paragraph>' );
 
 
 			showPanelSpy = sandbox.spy( contextualToolbar, 'show' );
 			showPanelSpy = sandbox.spy( contextualToolbar, 'show' );
 			hidePanelSpy = sandbox.spy( contextualToolbar, 'hide' );
 			hidePanelSpy = sandbox.spy( contextualToolbar, 'hide' );
@@ -402,7 +405,7 @@ describe( 'ContextualToolbar', () => {
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
 
 
-			editor.document.selection.fire( 'change:range', { directChange: true } );
+			selection.fire( 'change:range', { directChange: true } );
 
 
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( hidePanelSpy );
 			sinon.assert.calledOnce( hidePanelSpy );
@@ -414,7 +417,7 @@ describe( 'ContextualToolbar', () => {
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
 
 
-			editor.document.selection.fire( 'change:range', { directChange: false } );
+			selection.fire( 'change:range', { directChange: false } );
 
 
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
@@ -427,10 +430,10 @@ describe( 'ContextualToolbar', () => {
 			sinon.assert.notCalled( hidePanelSpy );
 			sinon.assert.notCalled( hidePanelSpy );
 
 
 			// Collapse range silently (without firing `change:range` { directChange: true } event).
 			// Collapse range silently (without firing `change:range` { directChange: true } event).
-			const range = editor.document.selection._ranges[ 0 ];
+			const range = selection._ranges[ 0 ];
 			range.end = range.start;
 			range.end = range.start;
 
 
-			editor.document.selection.fire( 'change:range', { directChange: false } );
+			selection.fire( 'change:range', { directChange: false } );
 
 
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( showPanelSpy );
 			sinon.assert.calledOnce( hidePanelSpy );
 			sinon.assert.calledOnce( hidePanelSpy );
@@ -478,7 +481,7 @@ describe( 'ContextualToolbar', () => {
 			const spy = sandbox.spy();
 			const spy = sandbox.spy();
 
 
 			contextualToolbar.on( 'show', spy );
 			contextualToolbar.on( 'show', spy );
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.show();
 			contextualToolbar.show();
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
@@ -487,7 +490,7 @@ describe( 'ContextualToolbar', () => {
 		it( 'should not show the panel when `show` event is stopped', () => {
 		it( 'should not show the panel when `show` event is stopped', () => {
 			const balloonAddSpy = sandbox.spy( balloon, 'add' );
 			const balloonAddSpy = sandbox.spy( balloon, 'add' );
 
 
-			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+			setData( model, '<paragraph>b[a]r</paragraph>' );
 
 
 			contextualToolbar.on( 'show', evt => evt.stop(), { priority: 'high' } );
 			contextualToolbar.on( 'show', evt => evt.stop(), { priority: 'high' } );
 
 
@@ -497,7 +500,6 @@ describe( 'ContextualToolbar', () => {
 	} );
 	} );
 
 
 	function stubSelectionRects( rects ) {
 	function stubSelectionRects( rects ) {
-		const editingView = editor.editing.view;
 		const originalViewRangeToDom = editingView.domConverter.viewRangeToDom;
 		const originalViewRangeToDom = editingView.domConverter.viewRangeToDom;
 
 
 		// Mock selection rect.
 		// Mock selection rect.