浏览代码

Allow to remove TextAlternative balloon when is in not visible stack.

Oskar Wróbel 6 年之前
父节点
当前提交
64dcb15202

+ 12 - 2
packages/ckeditor5-image/src/imagetextalternative/imagetextalternativeui.js

@@ -163,7 +163,7 @@ export default class ImageTextAlternativeUI extends Plugin {
 		const command = editor.commands.get( 'imageTextAlternative' );
 		const labeledInput = this._form.labeledInput;
 
-		if ( !this._balloon.hasView( this._form ) ) {
+		if ( !this._isInBalloon ) {
 			this._balloon.add( {
 				view: this._form,
 				position: getBalloonPositionData( editor )
@@ -187,7 +187,7 @@ export default class ImageTextAlternativeUI extends Plugin {
 	 * @private
 	 */
 	_hideForm( focusEditable ) {
-		if ( !this._isVisible ) {
+		if ( !this._isInBalloon ) {
 			return;
 		}
 
@@ -213,4 +213,14 @@ export default class ImageTextAlternativeUI extends Plugin {
 	get _isVisible() {
 		return this._balloon.visibleView === this._form;
 	}
+
+	/**
+	 * Returns `true` when the {@link #_form} is in the {@link #_balloon}.
+	 *
+	 * @private
+	 * @type {Boolean}
+	 */
+	get _isInBalloon() {
+		return this._balloon.hasView( this._form );
+	}
 }

+ 26 - 1
packages/ckeditor5-image/tests/imagetextalternative/imagetextalternativeui.js

@@ -9,6 +9,7 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest
 import Image from '../../src/image';
 import ImageTextAlternativeEditing from '../../src/imagetextalternative/imagetextalternativeediting';
 import ImageTextAlternativeUI from '../../src/imagetextalternative/imagetextalternativeui';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import View from '@ckeditor/ckeditor5-ui/src/view';
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
@@ -24,7 +25,7 @@ describe( 'ImageTextAlternativeUI', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ ImageTextAlternativeEditing, ImageTextAlternativeUI, Image ]
+				plugins: [ ImageTextAlternativeEditing, ImageTextAlternativeUI, Image, Paragraph ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -191,6 +192,30 @@ describe( 'ImageTextAlternativeUI', () => {
 			sinon.assert.notCalled( buttonFocusSpy );
 		} );
 
+		it( 'should be removed from balloon when is in not visible stack', () => {
+			setData( model, '<paragraph>foo</paragraph>[<image src="" alt="foo bar"></image>]' );
+
+			editor.ui.componentFactory.create( 'imageTextAlternative' ).fire( 'execute' );
+
+			const customView = new View();
+
+			balloon.add( {
+				view: customView,
+				position: { target: {} },
+				stackId: 'custom'
+			} );
+
+			balloon.showStack( 'custom' );
+
+			model.change( writer => {
+				const root = model.document.getRoot();
+
+				writer.setSelection( root.getChild( 0 ), 0 );
+			} );
+
+			expect( balloon.hasView( form ) ).to.equal( false );
+		} );
+
 		describe( 'integration with the editor selection (ui#update event)', () => {
 			it( 'should re-position the form', () => {
 				setData( model, '[<image src=""></image>]' );