Jelajahi Sumber

Minor refactoring (comments, order).

Piotrek Koszuliński 5 tahun lalu
induk
melakukan
c0d7683e5c
1 mengubah file dengan 26 tambahan dan 20 penghapusan
  1. 26 20
      packages/ckeditor5-table/src/ui/colorinputview.js

+ 26 - 20
packages/ckeditor5-table/src/ui/colorinputview.js

@@ -135,30 +135,11 @@ export default class ColorInputView extends View {
 
 		this.on(
 			'change:value',
-			( ev, n, inputValue ) => this._setInputValue( inputValue ),
+			( evt, name, inputValue ) => this._setInputValue( inputValue ),
 			{ priority: 'high' }
 		);
 	}
 
-	/**
-	 * Sets {@link #_inputView}'s value property to the color value or color label,
-	 * if there is one and the user is not typing.
-	 *
-	 * @private
-	 * @param {String} inputValue Color value to be set.
-	 */
-	_setInputValue( inputValue ) {
-		if ( !this._stillTyping ) {
-			// Check if the value matches one of our defined colors.
-			const mappedColor = this.options.colorDefinitions.find( def => inputValue === def.color );
-			if ( mappedColor ) {
-				this._inputView.value = mappedColor.label;
-			} else {
-				this._inputView.value = inputValue || '';
-			}
-		}
-	}
-
 	/**
 	 * Focuses the input.
 	 */
@@ -300,4 +281,29 @@ export default class ColorInputView extends View {
 
 		return colorGrid;
 	}
+
+	/**
+	 * Sets {@link #_inputView}'s value property to the color value or color label,
+	 * if there is one and the user is not typing.
+	 *
+	 * Handles cases like:
+	 *
+	 * * Someone picks the color in the grid.
+	 * * The color is set from the plugin level.
+	 *
+	 * @private
+	 * @param {String} inputValue Color value to be set.
+	 */
+	_setInputValue( inputValue ) {
+		if ( !this._stillTyping ) {
+			// Check if the value matches one of our defined colors.
+			const mappedColor = this.options.colorDefinitions.find( def => inputValue === def.color );
+
+			if ( mappedColor ) {
+				this._inputView.value = mappedColor.label;
+			} else {
+				this._inputView.value = inputValue || '';
+			}
+		}
+	}
 }