Przeglądaj źródła

Merge pull request #197 from ckeditor/t/ckeditor5-core/130

Internal: Used the `EditorUI#update` event instead of `View#render` to attach the UI components (see ckeditor/ckeditor5-core#130).
Aleksander Nowodzinski 7 lat temu
rodzic
commit
6b72027613

+ 12 - 13
packages/ckeditor5-link/src/linkui.js

@@ -336,8 +336,8 @@ export default class LinkUI extends Plugin {
 			}
 		}
 
-		// Begin responding to view#render once the UI is added.
-		this._startUpdatingUIOnViewRender();
+		// Begin responding to ui#update once the UI is added.
+		this._startUpdatingUI();
 	}
 
 	/**
@@ -352,9 +352,9 @@ export default class LinkUI extends Plugin {
 			return;
 		}
 
-		const editingView = this.editor.editing.view;
+		const editor = this.editor;
 
-		this.stopListening( editingView, 'render' );
+		this.stopListening( editor.ui, 'update' );
 
 		// Remove form first because it's on top of the stack.
 		this._removeFormView();
@@ -363,26 +363,25 @@ export default class LinkUI extends Plugin {
 		this._balloon.remove( this.actionsView );
 
 		// Make sure the focus always gets back to the editable.
-		editingView.focus();
+		editor.editing.view.focus();
 	}
 
 	/**
-	 * Makes the UI react to the {@link module:engine/view/view~View#event:render} in the view to
-	 * reposition itself as the document changes.
+	 * Makes the UI react to the {@link module:core/editor/editorui~EditorUI#event:update} event to
+	 * reposition itself when the editor ui should be refreshed.
 	 *
-	 * See: {@link #_hideUI} to learn when the UI stops reacting to the `render` event.
+	 * See: {@link #_hideUI} to learn when the UI stops reacting to the `update` event.
 	 *
 	 * @protected
 	 */
-	_startUpdatingUIOnViewRender() {
+	_startUpdatingUI() {
 		const editor = this.editor;
-		const editing = editor.editing;
-		const editingView = editing.view;
+		const viewDocument = editor.editing.view.document;
 
 		let prevSelectedLink = this._getSelectedLinkElement();
 		let prevSelectionParent = getSelectionParent();
 
-		this.listenTo( editingView, 'render', () => {
+		this.listenTo( editor.ui, 'update', () => {
 			const selectedLink = this._getSelectedLinkElement();
 			const selectionParent = getSelectionParent();
 
@@ -415,7 +414,7 @@ export default class LinkUI extends Plugin {
 		} );
 
 		function getSelectionParent() {
-			return editingView.document.selection.focus.getAncestors()
+			return viewDocument.selection.focus.getAncestors()
 				.reverse()
 				.find( node => node.is( 'element' ) );
 		}

+ 7 - 8
packages/ckeditor5-link/tests/linkui.js

@@ -246,7 +246,7 @@ describe( 'LinkUI', () => {
 			expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
 		} );
 
-		describe( 'response to view#change', () => {
+		describe( 'response to ui#update', () => {
 			let view, viewDocument;
 
 			beforeEach( () => {
@@ -254,17 +254,17 @@ describe( 'LinkUI', () => {
 				viewDocument = view.document;
 			} );
 
-			it( 'should not duplicate #change listeners', () => {
+			it( 'should not duplicate #update listeners', () => {
 				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 
 				linkUIFeature._showUI();
-				view.render();
+				editor.ui.fire( 'update' );
 				linkUIFeature._hideUI();
 
 				linkUIFeature._showUI();
-				view.render();
+				editor.ui.fire( 'update' );
 				sinon.assert.calledTwice( spy );
 			} );
 
@@ -301,7 +301,6 @@ describe( 'LinkUI', () => {
 				linkUIFeature._showUI();
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 
-				// Fires #render.
 				const root = viewDocument.getRoot();
 				const text = root.getChild( 0 ).getChild( 0 );
 
@@ -414,12 +413,12 @@ describe( 'LinkUI', () => {
 			} ).to.not.throw();
 		} );
 
-		it( 'should clear #render listener from the ViewDocument', () => {
+		it( 'should clear ui#update listener from the ViewDocument', () => {
 			const spy = sinon.spy();
 
-			linkUIFeature.listenTo( editor.editing.view, 'render', spy );
+			linkUIFeature.listenTo( editor.ui, 'update', spy );
 			linkUIFeature._hideUI();
-			editor.editing.view.change( () => {} );
+			editor.ui.fire( 'update' );
 
 			sinon.assert.notCalled( spy );
 		} );