瀏覽代碼

Internal: Slightly different way of avoiding commit execution when there's no state.

Marek Lewandowski 6 年之前
父節點
當前提交
85c2e9402e
共有 1 個文件被更改,包括 11 次插入6 次删除
  1. 11 6
      packages/ckeditor5-widget/src/widgetresize/resizer.js

+ 11 - 6
packages/ckeditor5-widget/src/widgetresize/resizer.js

@@ -71,6 +71,14 @@ export default class Resizer {
 		this.decorate( 'cancel' );
 		this.decorate( 'commit' );
 		this.decorate( 'updateSize' );
+
+		this.on( 'commit', event => {
+			// State might not be initialized (#5195).
+			if ( !this.state.proposedWidth ) {
+				this._cleanup();
+				event.stop();
+			}
+		}, { priority: 'high' } );
 	}
 
 	/**
@@ -157,13 +165,10 @@ export default class Resizer {
 	 * @fires commit
 	 */
 	commit() {
-		if ( this.state.proposedWidth ) {
-			// State might not be initialized (#5195).
-			const unit = this._options.unit;
-			const newValue = ( unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth ) + this._options.unit;
+		const unit = this._options.unit;
+		const newValue = ( unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth ) + this._options.unit;
 
-			this._options.onCommit( newValue );
-		}
+		this._options.onCommit( newValue );
 
 		this._cleanup();
 	}