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

Changed the way of updating ContextualBalloon position.

Oskar Wróbel 8 лет назад
Родитель
Сommit
66268e122e

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

@@ -159,14 +159,14 @@ export default class ContextualBalloon extends Plugin {
 	}
 
 	/**
-	 * Updates the position of the balloon panel according to the given position data
-	 * or position data of the first view in the stack.
+	 * Updates the position of the balloon using position data of the first visible view in the stack.
+	 * When new position data is given then position data of currently visible panel will be updated.
 	 *
 	 * @param {module:utils/dom/position~Options} [position] position options.
 	 */
 	updatePosition( position ) {
 		if ( position ) {
-			this._stack.values().next().value.position = position;
+			this._stack.get( this.visibleView ).position = position;
 		}
 
 		this.view.attachTo( this._getBalloonPosition() );

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

@@ -267,18 +267,36 @@ describe( 'ContextualBalloon', () => {
 			expect( balloon.view.attachTo.firstCall.args[ 0 ] ).to.deep.equal( { target: 'fake' } );
 		} );
 
-		it( 'should attach balloon to the target using new position options', () => {
+		it( 'should set given position to the currently visible view and use position from the first view in the stack #1', () => {
 			balloon.view.attachTo.reset();
 
 			balloon.updatePosition( { target: 'new' } );
 
 			expect( balloon.view.attachTo.calledOnce );
 			expect( balloon.view.attachTo.firstCall.args[ 0 ] ).to.deep.equal( { target: 'new' } );
+		} );
+
+		it( 'should set given position to the currently visible view and use position from the first view in the stack #2', () => {
+			balloon.add( {
+				view: viewB,
+				position: {
+					target: 'other'
+				}
+			} );
+
+			balloon.view.attachTo.reset();
+
+			balloon.updatePosition( { target: 'new' } );
+
+			expect( balloon.view.attachTo.calledOnce );
+			expect( balloon.view.attachTo.firstCall.args[ 0 ] ).to.deep.equal( { target: 'fake' } );
+
+			balloon.remove( viewA );
 
 			balloon.updatePosition();
 
 			expect( balloon.view.attachTo.calledTwice );
-			expect( balloon.view.attachTo.firstCall.args[ 0 ] ).to.deep.equal( { target: 'new' } );
+			expect( balloon.view.attachTo.secondCall.args[ 0 ] ).to.deep.equal( { target: 'new' } );
 		} );
 
 		it( 'should throw an error when there is no given view in the stack', () => {