瀏覽代碼

Used decorator for ContextualToolbar#show method.

Oskar Wróbel 8 年之前
父節點
當前提交
cf73eb067f

+ 12 - 21
packages/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar.js

@@ -81,8 +81,8 @@ export default class ContextualToolbar extends Plugin {
 		this._handleFocusChange();
 
 		// The appearance of the ContextualToolbar method is event–driven.
-		// It is possible to stop the #show event and thus prevent the toolbar from showing up.
-		this.on( 'show', () => this._show(), { priority: 'low' } );
+		// It is possible to stop the #show event and this prevent the toolbar from showing up.
+		this.decorate( 'show' );
 	}
 
 	/**
@@ -158,25 +158,6 @@ export default class ContextualToolbar extends Plugin {
 			return;
 		}
 
-		this.fire( 'show' );
-	}
-
-	/**
-	 * Hides the toolbar.
-	 */
-	hide() {
-		if ( this._balloon.hasView( this.toolbarView ) ) {
-			this.stopListening( this.editor.editing.view, 'render' );
-			this._balloon.remove( this.toolbarView );
-		}
-	}
-
-	/**
-	 * Shows of the toolbar if the {@link #event:show} has not been stopped.
-	 *
-	 * @private
-	 */
-	_show() {
 		// Don not show the toolbar when all components inside are disabled
 		// see https://github.com/ckeditor/ckeditor5-ui/issues/269.
 		if ( Array.from( this.toolbarView.items ).every( item => item.isEnabled !== undefined && !item.isEnabled ) ) {
@@ -198,6 +179,16 @@ export default class ContextualToolbar extends Plugin {
 	}
 
 	/**
+	 * Hides the toolbar.
+	 */
+	hide() {
+		if ( this._balloon.hasView( this.toolbarView ) ) {
+			this.stopListening( this.editor.editing.view, 'render' );
+			this._balloon.remove( this.toolbarView );
+		}
+	}
+
+	/**
 	 * Returns positioning options for the {@link #_balloon}. They control the way balloon is attached
 	 * to the selection.
 	 *

+ 1 - 1
packages/ckeditor5-ui/tests/manual/contextualtoolbar/contextualtoolbar.js

@@ -27,7 +27,7 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
 		if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
 			evt.stop();
 		}
-	} );
+	}, { priority: 'high' } );
 } )
 .catch( err => {
 	console.error( err.stack );

+ 1 - 1
packages/ckeditor5-ui/tests/toolbar/contextual/contextualtoolbar.js

@@ -447,7 +447,7 @@ describe( 'ContextualToolbar', () => {
 
 			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
 
-			contextualToolbar.on( 'show', evt => evt.stop() );
+			contextualToolbar.on( 'show', evt => evt.stop(), { priority: 'high' } );
 
 			contextualToolbar.show();
 			sinon.assert.notCalled( balloonAddSpy );