浏览代码

Other: Made the ContextualBalloon always use the position of the topmost view in the stack (see: ckeditor/ckeditor5-table#28).

Aleksander Nowodzinski 7 年之前
父节点
当前提交
63c9f1c567

+ 2 - 3
packages/ckeditor5-ui/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 ) {

+ 5 - 5
packages/ckeditor5-ui/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
 			} );