浏览代码

Add checkmark in both color grid sections.

Mateusz Samsel 6 年之前
父节点
当前提交
5988fa7206
共有 2 个文件被更改,包括 10 次插入17 次删除
  1. 5 11
      packages/ckeditor5-font/src/ui/colortableview.js
  2. 5 6
      packages/ckeditor5-font/tests/ui/colortableview.js

+ 5 - 11
packages/ckeditor5-font/src/ui/colortableview.js

@@ -222,23 +222,17 @@ export default class ColorTableView extends View {
 
 	/**
 	 * Method refresh state of `selectedColor` in single or both {@link module:ui/colorgrid/colorgrid~ColorGridView}
-	 * available in {@link module:font/ui/colortableview~ColorTableView}. It guarantees that selection will occur only in one of them.
+	 * available in {@link module:font/ui/colortableview~ColorTableView}.
 	 */
 	updateSelectedColors() {
 		const documentColorsGrid = this.documentColorsGrid;
 		const staticColorsGrid = this.staticColorsGrid;
 		const selectedColor = this.selectedColor;
 
-		if ( !this.documentColors.isEmpty ) {
-			if ( this.documentColors.hasColor( selectedColor ) ) {
-				staticColorsGrid.selectedColor = null;
-				documentColorsGrid.selectedColor = selectedColor;
-			} else {
-				staticColorsGrid.selectedColor = selectedColor;
-				documentColorsGrid.selectedColor = null;
-			}
-		} else {
-			staticColorsGrid.selectedColor = selectedColor;
+		staticColorsGrid.selectedColor = selectedColor;
+
+		if ( documentColorsGrid ) {
+			documentColorsGrid.selectedColor = selectedColor;
 		}
 	}
 

+ 5 - 6
packages/ckeditor5-font/tests/ui/colortableview.js

@@ -445,17 +445,17 @@ describe( 'ColorTableView', () => {
 
 			dropdown.isOpen = true;
 
-			expect( staticColorsGrid.selectedColor ).to.be.null;
+			expect( staticColorsGrid.selectedColor ).to.equal( 'red' );
 			expect( documentColorsGrid.selectedColor ).to.equal( 'red' );
 
 			const redStaticColorTile = staticColorsGrid.items.find( tile => tile.color === 'red' );
 			const redDocumentColorTile = documentColorsGrid.items.get( 0 );
 
-			expect( redStaticColorTile.isOn ).to.be.false;
+			expect( redStaticColorTile.isOn ).to.be.true;
 			expect( redDocumentColorTile.isOn ).to.be.true;
 		} );
 
-		it( 'checkmark is present in static colors', () => {
+		it( 'checkmark is present in static colors when there is no space for document color', () => {
 			const command = editor.commands.get( 'testColorCommand' );
 
 			setModelData( model,
@@ -469,13 +469,12 @@ describe( 'ColorTableView', () => {
 			dropdown.isOpen = true;
 
 			expect( staticColorsGrid.selectedColor ).to.equal( '#00FF00' );
-			expect( documentColorsGrid.selectedColor ).to.be.null;
 
 			const redStaticColorTile = staticColorsGrid.items.find( tile => tile.color === '#00FF00' );
-			const redDocumentColorTile = documentColorsGrid.items.get( 0 );
+			const activeDocumentColorTile = documentColorsGrid.items.find( tile => tile.isOn );
 
 			expect( redStaticColorTile.isOn ).to.be.true;
-			expect( redDocumentColorTile.isOn ).to.be.false;
+			expect( activeDocumentColorTile ).to.be.undefined;
 		} );
 	} );