소스 검색

Renamed HeadingCommand's private method _updateValue to public refreshValue. Removed schema.objects checking from _checkEnabled method.

Szymon Kupś 8 년 전
부모
커밋
51a7dc92d7
3개의 변경된 파일19개의 추가작업 그리고 26개의 파일을 삭제
  1. 3 12
      packages/ckeditor5-heading/src/headingcommand.js
  2. 1 1
      packages/ckeditor5-heading/tests/heading.js
  3. 15 13
      packages/ckeditor5-heading/tests/headingcommand.js

+ 3 - 12
packages/ckeditor5-heading/src/headingcommand.js

@@ -42,7 +42,7 @@ export default class HeadingCommand extends Command {
 
 		// Update current value each time changes are done on document.
 		this.listenTo( editor.document, 'changesDone', () => {
-			this._updateValue();
+			this.refreshValue();
 			this.refreshState();
 		} );
 
@@ -112,10 +112,8 @@ export default class HeadingCommand extends Command {
 
 	/**
 	 * Updates command's {@link #value value} based on current selection.
-	 *
-	 * @private
 	 */
-	_updateValue() {
+	refreshValue() {
 		const block = first( this.editor.document.selection.getSelectedBlocks() );
 
 		this.value = !!block && block.is( this.modelElement );
@@ -127,17 +125,10 @@ export default class HeadingCommand extends Command {
 	_checkEnabled() {
 		const block = first( this.editor.document.selection.getSelectedBlocks() );
 
-		if ( !block ) {
-			return false;
-		}
-
-		const schema = this.editor.document.schema;
-		const isAllowed = schema.check( {
+		return !!block && this.editor.document.schema.check( {
 			name: this.modelElement,
 			inside: Position.createBefore( block )
 		} );
-
-		return isAllowed && !schema.objects.has( block.name );
 	}
 }
 

+ 1 - 1
packages/ckeditor5-heading/tests/heading.js

@@ -60,7 +60,7 @@ describe( 'Heading', () => {
 	describe( 'init()', () => {
 		it( 'should register options feature component', () => {
 			const dropdown = editor.ui.componentFactory.create( 'headings' );
-			//
+
 			expect( dropdown ).to.be.instanceOf( DropdownView );
 			expect( dropdown.buttonView.isEnabled ).to.be.true;
 			expect( dropdown.buttonView.isOn ).to.be.undefined;

+ 15 - 13
packages/ckeditor5-heading/tests/headingcommand.js

@@ -37,11 +37,6 @@ describe( 'HeadingCommand', () => {
 			schema.allow( { name: 'notBlock', inside: '$root' } );
 			schema.allow( { name: '$text', inside: 'notBlock' } );
 
-			schema.registerItem( 'object' );
-			schema.allow( { name: 'object', inside: '$root' } );
-			schema.allow( { name: '$text', inside: 'object' } );
-			schema.objects.add( 'object' );
-
 			root = document.getRoot();
 		} );
 	} );
@@ -96,6 +91,19 @@ describe( 'HeadingCommand', () => {
 
 				expect( commands[ modelElement ].value ).to.be.false;
 			} );
+
+			it( 'should be refreshed after calling refreshValue()', () => {
+				const command = commands[ modelElement ];
+				setData( document, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
+				const element = document.getRoot().getChild( 1 );
+
+				// Purposely not putting it in `document.enqueueChanges` to update command manually.
+				document.selection.setRanges( [ Range.createIn( element ) ] );
+
+				expect( command.value ).to.be.true;
+				command.refreshValue();
+				expect( command.value ).to.be.false;
+			} );
 		}
 	} );
 
@@ -243,14 +251,8 @@ describe( 'HeadingCommand', () => {
 					expect( command.isEnabled ).to.be.false;
 				} );
 
-				it( 'should be disabled if inside object', () => {
-					setData( document, '<object>f{}oo</object>' );
-
-					expect( command.isEnabled ).to.be.false;
-				} );
-
-				it( 'should be disabled if selection is placed on object', () => {
-					setData( document, '[<object>foo</object>]' );
+				it( 'should be disabled if selection is placed on non-block', () => {
+					setData( document, '[<notBlock>foo</notBlock>]' );
 
 					expect( command.isEnabled ).to.be.false;
 				} );