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

Fix: Do not hide the toolbar when is focused.

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

+ 7 - 4
packages/ckeditor5-ui/src/toolbar/balloon/balloontoolbar.js

@@ -81,11 +81,14 @@ export default class BalloonToolbar extends Plugin {
 		const editor = this.editor;
 		const editor = this.editor;
 		const selection = editor.model.document.selection;
 		const selection = editor.model.document.selection;
 
 
-		// Show/hide the toolbar when on editable focus/blur.
-		this.listenTo( editor.editing.view.document, 'change:isFocused', ( evt, name, isFocused ) => {
-			if ( !isFocused && this._balloon.visibleView === this.toolbarView ) {
+		// Show/hide the toolbar on editable focus/blur.
+		this.listenTo( editor.editing.view.document, 'change:isFocused', ( evt, name, isEditableFocused ) => {
+			const isToolbarFocused = this.toolbarView.focusTracker.isFocused;
+			const isToolbarVisible = this._balloon.visibleView === this.toolbarView;
+
+			if ( !isEditableFocused && !isToolbarFocused && isToolbarVisible ) {
 				this.hide();
 				this.hide();
-			} else if ( isFocused ) {
+			} else if ( isEditableFocused ) {
 				this.show();
 				this.show();
 			}
 			}
 		} );
 		} );

+ 19 - 0
packages/ckeditor5-ui/tests/toolbar/balloon/balloontoolbar.js

@@ -477,6 +477,25 @@ describe( 'BalloonToolbar', () => {
 			stub.restore();
 			stub.restore();
 		} );
 		} );
 
 
+		it( 'should not hide on editable blur when #toolbarView gets focus', () => {
+			editingView.document.isFocused = true;
+
+			balloonToolbar.fire( '_selectionChangeDebounced' );
+
+			const stub = sandbox.stub( balloon, 'visibleView' ).get( () => balloonToolbar.toolbarView );
+
+			sinon.assert.calledOnce( showPanelSpy );
+			sinon.assert.notCalled( hidePanelSpy );
+
+			balloonToolbar.toolbarView.focusTracker.isFocused = true;
+			editingView.document.isFocused = false;
+
+			sinon.assert.calledOnce( showPanelSpy );
+			sinon.assert.notCalled( hidePanelSpy );
+
+			stub.restore();
+		} );
+
 		it( 'should not hide on editable blur when #toolbarView is not visible', () => {
 		it( 'should not hide on editable blur when #toolbarView is not visible', () => {
 			editingView.document.isFocused = true;
 			editingView.document.isFocused = true;