diff --git a/src/panel/balloon/contextualballoon.js b/src/panel/balloon/contextualballoon.js index 101196a0..65082eca 100644 --- a/src/panel/balloon/contextualballoon.js +++ b/src/panel/balloon/contextualballoon.js @@ -10,7 +10,6 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; import BalloonPanelView from './balloonpanelview'; import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror'; -import first from '@ckeditor/ckeditor5-utils/src/first'; /** * Provides the common contextual balloon panel for the editor. @@ -213,14 +212,14 @@ export default class ContextualBalloon extends Plugin { } /** - * Returns position options of the first view in the stack. + * Returns position options of the last view in the stack. * This keeps the balloon in the same position when view is changed. * * @private * @returns {module:utils/dom/position~Options} */ _getBalloonPosition() { - let position = first( this._stack.values() ).position; + let position = Array.from( this._stack.values() ).pop().position; // Use the default limiter if none has been specified. if ( position && !position.limiter ) { diff --git a/tests/panel/balloon/contextualballoon.js b/tests/panel/balloon/contextualballoon.js index f94adaa1..f6d69803 100644 --- a/tests/panel/balloon/contextualballoon.js +++ b/tests/panel/balloon/contextualballoon.js @@ -258,7 +258,7 @@ describe( 'ContextualBalloon', () => { expect( balloon.view.content.get( 0 ) ).to.deep.equal( viewB ); } ); - it( 'should keep balloon at the same position after adding next view', () => { + it( 'should use the position of the last view in the stack', () => { balloon.add( { view: viewB, position: { target: 'other' } @@ -272,7 +272,7 @@ describe( 'ContextualBalloon', () => { } ); sinon.assert.calledWithMatch( balloon.view.pin.secondCall, { - target: 'fake', + target: 'other', limiter: balloon.positionLimiter } ); } ); @@ -399,7 +399,7 @@ describe( 'ContextualBalloon', () => { } ); describe( 'updatePosition()', () => { - it( 'should attach balloon to the target using position option from the first view in the stack', () => { + it( 'should attach balloon to the target using position option from the last view in the stack', () => { balloon.add( { view: viewB, position: { @@ -413,7 +413,7 @@ describe( 'ContextualBalloon', () => { expect( balloon.view.pin.calledOnce ); sinon.assert.calledWithMatch( balloon.view.pin.firstCall, { - target: 'fake', + target: 'other', limiter: balloon.positionLimiter } ); } ); @@ -444,7 +444,7 @@ describe( 'ContextualBalloon', () => { expect( balloon.view.pin.calledOnce ); sinon.assert.calledWithMatch( balloon.view.pin.firstCall, { - target: 'fake', + target: 'new', limiter: balloon.positionLimiter } );