ソースを参照

Simplified the code and improved some docs.

Oskar Wróbel 7 年 前
コミット
80da6b4a7b

+ 3 - 5
packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js

@@ -242,17 +242,15 @@ export default class BlockToolbar extends Plugin {
 		const model = editor.model;
 		const view = editor.editing.view;
 
-		// Hides the button when editor is not focused.
+		// Hides the button when the editor is not focused.
 		if ( !editor.ui.focusTracker.isFocused ) {
 			this._hideButton();
 
 			return;
 		}
 
-		// Hides button when the editor switches to the read-only mode.
-		// Do not hide when panel is already visible to avoid a confusing UX when the panel
-		// unexpectedly disappears.
-		if ( editor.isReadOnly && !this.panelView.isVisible ) {
+		// Hides the button when the editor switches to the read-only mode.
+		if ( editor.isReadOnly ) {
 			this._hideButton();
 
 			return;

+ 6 - 6
packages/ckeditor5-ui/tests/toolbar/block/blocktoolbar.js

@@ -365,7 +365,7 @@ describe( 'BlockToolbar', () => {
 			expect( blockToolbar.panelView.isVisible ).to.be.false;
 		} );
 
-		it( 'should not hide the open panel on a indirect selection change', () => {
+		it( 'should not hide the open panel on an indirect selection change', () => {
 			blockToolbar.panelView.isVisible = true;
 
 			editor.model.document.selection.fire( 'change:range', { directChange: false } );
@@ -373,11 +373,11 @@ describe( 'BlockToolbar', () => {
 			expect( blockToolbar.panelView.isVisible ).to.be.true;
 		} );
 
-		it( 'should hide the UI when editor switched to readonly when the panel is not visible', () => {
+		it( 'should hide the UI when editor switched to readonly', () => {
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			blockToolbar.buttonView.isVisible = true;
-			blockToolbar.panelView.isVisible = false;
+			blockToolbar.panelView.isVisible = true;
 
 			editor.isReadOnly = true;
 
@@ -385,7 +385,7 @@ describe( 'BlockToolbar', () => {
 			expect( blockToolbar.panelView.isVisible ).to.be.false;
 		} );
 
-		it( 'should show the button when the editor switched from readonly', () => {
+		it( 'should show the button when the editor switched back from readonly', () => {
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			expect( blockToolbar.buttonView.isVisible ).to.true;
@@ -399,7 +399,7 @@ describe( 'BlockToolbar', () => {
 			expect( blockToolbar.buttonView.isVisible ).to.be.true;
 		} );
 
-		it( 'should show/hide the button on editor focus/blur', () => {
+		it( 'should show/hide the button on the editor focus/blur', () => {
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			editor.ui.focusTracker.isFocused = true;
@@ -415,7 +415,7 @@ describe( 'BlockToolbar', () => {
 			expect( blockToolbar.buttonView.isVisible ).to.true;
 		} );
 
-		it( 'should hide the UI when editor switched to readonly when the panel is not visible', () => {
+		it( 'should hide the UI when the editor switched to the readonly when the panel is not visible', () => {
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			blockToolbar.buttonView.isVisible = true;