Răsfoiți Sursa

BalloonPanelView#pin should show the balloon and BalloonPanelView#unpin should hide it.

Aleksander Nowodzinski 8 ani în urmă
părinte
comite
044f23cb33

+ 3 - 4
packages/ckeditor5-ui/src/panel/balloon/balloonpanelview.js

@@ -210,10 +210,7 @@ export default class BalloonPanelView extends View {
 			}
 		};
 
-		// If the panel is already visible, start pinning immediately.
-		if ( this.isVisible ) {
-			this._startPinning( options );
-		}
+		this._startPinning( options );
 
 		// Control the state of the listeners depending on whether the panel is visible
 		// or not.
@@ -234,6 +231,8 @@ export default class BalloonPanelView extends View {
 			this.stopListening( this, 'change:isVisible', this._pinWhenIsVisibleCallback );
 
 			this._pinWhenIsVisibleCallback = null;
+
+			this.hide();
 		}
 	}
 

+ 0 - 1
packages/ckeditor5-ui/tests/manual/tickets/170/1.js

@@ -52,7 +52,6 @@ ClassicEditor.create( document.querySelector( '#editor-stick' ), {
 	editor.ui.view.element.querySelector( '.ck-editor__editable' ).scrollTop = 360;
 
 	panel.init().then( () => {
-		panel.show();
 		panel.pin( {
 			target: editor.ui.view.element.querySelector( '.ck-editor__editable p strong' ),
 			limiter: editor.ui.view.editableElement

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

@@ -446,26 +446,27 @@ describe( 'BalloonPanelView', () => {
 		} );
 
 		describe( 'pin()', () => {
-			it( 'should not show the balloon', () => {
-				const showSpy = sinon.spy( view, 'show' );
+			it( 'should show the balloon', () => {
+				const spy = sinon.spy( view, 'show' );
 
 				view.hide();
 
 				view.pin( { target, limiter } );
-				sinon.assert.notCalled( showSpy );
+				sinon.assert.calledOnce( spy );
 			} );
 
 			it( 'should start pinning when the balloon is visible', () => {
-				view.hide();
 				view.pin( { target, limiter } );
+				sinon.assert.calledOnce( attachToSpy );
 
+				view.hide();
 				targetParent.dispatchEvent( new Event( 'scroll' ) );
 
 				view.show();
+				sinon.assert.calledTwice( attachToSpy );
 
 				targetParent.dispatchEvent( new Event( 'scroll' ) );
-
-				sinon.assert.calledTwice( attachToSpy );
+				sinon.assert.calledThrice( attachToSpy );
 			} );
 
 			it( 'should stop pinning when the balloon becomes invisible', () => {
@@ -603,13 +604,13 @@ describe( 'BalloonPanelView', () => {
 		} );
 
 		describe( 'unpin()', () => {
-			it( 'should not hide the balloon if pinned', () => {
-				const hideSpy = sinon.spy( view, 'hide' );
+			it( 'should hide the balloon if pinned', () => {
+				const spy = sinon.spy( view, 'hide' );
 
 				view.pin( { target, limiter } );
 				view.unpin();
 
-				sinon.assert.notCalled( hideSpy );
+				sinon.assert.calledOnce( spy );
 			} );
 
 			it( 'should stop attaching', () => {