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

Reduced attached render events.

Oskar Wróbel 8 лет назад
Родитель
Сommit
d78d4325e3
2 измененных файлов с 28 добавлено и 0 удалено
  1. 3 0
      packages/ckeditor5-link/src/link.js
  2. 25 0
      packages/ckeditor5-link/tests/link.js

+ 3 - 0
packages/ckeditor5-link/src/link.js

@@ -206,6 +206,9 @@ export default class Link extends Plugin {
 				// Then show panel but keep focus inside editor editable.
 				// Then show panel but keep focus inside editor editable.
 				this._showPanel();
 				this._showPanel();
 
 
+				// Avoid duplication of the same listener.
+				this.stopListening( viewDocument, 'render' );
+
 				// Start listen to view document changes and close the panel when selection will be moved
 				// Start listen to view document changes and close the panel when selection will be moved
 				// out of the actual link element.
 				// out of the actual link element.
 				this.listenTo( viewDocument, 'render', () => {
 				this.listenTo( viewDocument, 'render', () => {

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

@@ -325,6 +325,31 @@ describe( 'Link', () => {
 				expect( balloon.view.attachTo.calledOnce ).to.true;
 				expect( balloon.view.attachTo.calledOnce ).to.true;
 			} );
 			} );
 
 
+			it( 'should not duplicate `render` listener on `ViewDocument`', () => {
+				const observer = editor.editing.view.getObserver( ClickObserver );
+				const updatePositionSpy = testUtils.sinon.spy( balloon, 'updatePosition' );
+
+				editor.document.schema.allow( { name: '$text', inside: '$root' } );
+				setModelData( editor.document, '<$text linkHref="url">b[]ar</$text>' );
+
+				// Click at the same link more than once.
+				observer.fire( 'click', { target: document.body } );
+				observer.fire( 'click', { target: document.body } );
+				observer.fire( 'click', { target: document.body } );
+
+				sinon.assert.notCalled( updatePositionSpy );
+
+				const root = editor.editing.view.getRoot();
+				const text = root.getChild( 0 ).getChild( 0 );
+
+				// Move selection.
+				editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
+				editor.editing.view.render();
+
+				// Position should be updated only once.
+				sinon.assert.calledOnce( updatePositionSpy );
+			} );
+
 			it( 'should close when selection goes outside the link element', () => {
 			it( 'should close when selection goes outside the link element', () => {
 				const observer = editor.editing.view.getObserver( ClickObserver );
 				const observer = editor.editing.view.getObserver( ClickObserver );