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

Hide ImageTextAlternative balloon when image element has been removed by external change.

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

+ 6 - 3
packages/ckeditor5-image/src/imagetextalternative.js

@@ -15,6 +15,7 @@ import TextAlternativeFormView from './imagetextalternative/ui/textalternativefo
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import textAlternativeIcon from '@ckeditor/ckeditor5-core/theme/icons/low-vision.svg';
 import { repositionContextualBalloon, getBalloonPositionData } from './image/ui/utils';
+import { isImageWidgetSelected } from './image/utils';
 
 import '../theme/imagetextalternative/theme.scss';
 
@@ -119,9 +120,11 @@ export default class ImageTextAlternative extends Plugin {
 			cancel();
 		} );
 
-		// Reposition the balloon upon #render.
+		// Reposition the balloon or hide the form if image widget is no longer selected.
 		this.listenTo( editingView, 'render', () => {
-			if ( this._isVisible ) {
+			if ( !isImageWidgetSelected( editingView.selection ) ) {
+				this._hideForm();
+			} else if ( this._isVisible ) {
 				repositionContextualBalloon( editor );
 			}
 		}, { priority: 'low' } );
@@ -176,7 +179,7 @@ export default class ImageTextAlternative extends Plugin {
 	/**
 	 * Removes the {@link #_form} from the {@link #_balloon}.
 	 *
-	 * @param {Boolean} focusEditable Controls whether the editing view is focused afterwards.
+	 * @param {Boolean} [focusEditable=false] Controls whether the editing view is focused afterwards.
 	 * @private
 	 */
 	_hideForm( focusEditable ) {

+ 14 - 0
packages/ckeditor5-image/tests/imagetextalternative.js

@@ -168,6 +168,20 @@ describe( 'ImageTextAlternative', () => {
 				editingView.fire( 'render' );
 				sinon.assert.calledOnce( spy );
 			} );
+
+			it( 'should hide the form when image widget is no longer selected', () => {
+				setData( doc, '[<image src=""></image>]' );
+				button.fire( 'execute' );
+
+				const spy = sinon.spy( balloon, 'remove' );
+
+				// EnqueueChanges automatically calls #render event.
+				doc.enqueueChanges( () => {
+					doc.batch( 'transparent' ).remove( doc.selection.getFirstRange() );
+				} );
+
+				sinon.assert.calledWithExactly( spy, form );
+			} );
 		} );
 
 		describe( 'integration with the editor focus', () => {