Explorar el Código

Add underscore to private method name, sort methods alphabeticlaly. Correct method's name in unit tests.

Mateusz Samsel hace 6 años
padre
commit
2130469b6f

+ 28 - 28
packages/ckeditor5-font/src/ui/colorui.js

@@ -143,6 +143,33 @@ export default class ColorUI extends Plugin {
 		} );
 	}
 
+	/**
+	 * Method adds the `color` to document colors list. If possible, it will attempt to use data from the
+	 * {@link #colorDefinitions} (label, color options). If color is found, then it is added to the
+	 * {@link module:font/ui/colortableview~ColorTableView#documentColors} model.
+	 * In other case it's created custom color, which is added to
+	 * {@link module:font/ui/colortableview~ColorTableView#documentColors} model.
+	 *
+	 * @private
+	 * @param {String} color String which stores value of recently applied color
+	 */
+	_addColorToDocumentColors( color ) {
+		const predefinedColor = this.colorTableView.colorDefinitions
+			.find( definition => definition.color === color );
+
+		if ( !predefinedColor ) {
+			this.colorTableView.documentColors.add( {
+				color,
+				label: color,
+				options: {
+					hasBorder: false
+				}
+			} );
+		} else {
+			this.colorTableView.documentColors.add( Object.assign( {}, predefinedColor ) );
+		}
+	}
+
 	/**
 	 * Method scans through editor's content and searches for text node attributes with the name defined in {@link #commandName}.
 	 * Found entries are set as document colors.
@@ -164,7 +191,7 @@ export default class ColorUI extends Plugin {
 			const range = model.createRangeIn( root );
 			for ( const node of range.getItems() ) {
 				if ( node.is( 'textProxy' ) && node.hasAttribute( this.componentName ) ) {
-					this.addColorToDocumentColors( node.getAttribute( this.componentName ) );
+					this._addColorToDocumentColors( node.getAttribute( this.componentName ) );
 					if ( documentColors.length >= maxCount ) {
 						return;
 					}
@@ -172,31 +199,4 @@ export default class ColorUI extends Plugin {
 			}
 		}
 	}
-
-	/**
-	 * Method adds the `color` to document colors list. If possible, it will attempt to use data from the
-	 * {@link #colorDefinitions} (label, color options). If color is found, then it is added to the
-	 * {@link module:font/ui/colortableview~ColorTableView#documentColors} model.
-	 * In other case it's created custom color, which is added to
-	 * {@link module:font/ui/colortableview~ColorTableView#documentColors} model.
-	 *
-	 * @private
-	 * @param {String} color String which stores value of recently applied color
-	 */
-	addColorToDocumentColors( color ) {
-		const predefinedColor = this.colorTableView.colorDefinitions
-			.find( definition => definition.color === color );
-
-		if ( !predefinedColor ) {
-			this.colorTableView.documentColors.add( {
-				color,
-				label: color,
-				options: {
-					hasBorder: false
-				}
-			} );
-		} else {
-			this.colorTableView.documentColors.add( Object.assign( {}, predefinedColor ) );
-		}
-	}
 }

+ 3 - 3
packages/ckeditor5-font/tests/ui/colorui.js

@@ -354,7 +354,7 @@ describe( 'ColorUI', () => {
 		} );
 	} );
 
-	describe( 'addColorToDocumentColors', () => {
+	describe( '_addColorToDocumentColors', () => {
 		let dropdown;
 
 		beforeEach( () => {
@@ -367,7 +367,7 @@ describe( 'ColorUI', () => {
 		} );
 
 		it( 'add custom color from not defined colors', () => {
-			testColorPlugin.addColorToDocumentColors( '#123456' );
+			testColorPlugin._addColorToDocumentColors( '#123456' );
 			expect( dropdown.colorTableView.documentColors.get( 0 ) ).to.deep.include( {
 				color: '#123456',
 				label: '#123456',
@@ -378,7 +378,7 @@ describe( 'ColorUI', () => {
 		} );
 
 		it( 'add already define color absed on color value', () => {
-			testColorPlugin.addColorToDocumentColors( 'rgb(255,255,255)' );
+			testColorPlugin._addColorToDocumentColors( 'rgb(255,255,255)' );
 			// Color values are kept without spaces.
 			expect( dropdown.colorTableView.documentColors.get( 0 ) ).to.deep.include( {
 				color: 'rgb(255,255,255)',