Browse Source

Minor fixes in paragraph command.

Szymon Kupś 8 years ago
parent
commit
429ca33571

+ 3 - 12
packages/ckeditor5-paragraph/src/paragraphcommand.js

@@ -9,6 +9,7 @@
 
 import Command from '@ckeditor/ckeditor5-core/src/command/command';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
+import first from '@ckeditor/ckeditor5-utils/src/first';
 
 /**
  * The paragraph command.
@@ -73,7 +74,7 @@ export default class ParagraphCommand extends Command {
 	 * @private
 	 */
 	_updateValue() {
-		const block = this._getSelectedBlock();
+		const block = first( this.editor.document.selection.getSelectedBlocks() );
 
 		this.value = !!block && block.is( 'paragraph' );
 	}
@@ -82,7 +83,7 @@ export default class ParagraphCommand extends Command {
 	 * @inheritDoc
 	 */
 	_checkEnabled() {
-		const block = this._getSelectedBlock();
+		const block = first( this.editor.document.selection.getSelectedBlocks() );
 
 		if ( !block ) {
 			return false;
@@ -96,14 +97,4 @@ export default class ParagraphCommand extends Command {
 
 		return isParagraphAllowed && !schema.objects.has( block.name );
 	}
-
-	/**
-	 * Returns currently selected block.
-	 *
-	 * @private
-	 * @returns {module:engine/model/element~Element}
-	 */
-	_getSelectedBlock() {
-		return this.editor.document.selection.getSelectedBlocks().next().value;
-	}
 }

+ 7 - 3
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -69,12 +69,16 @@ describe( 'ParagraphCommand', () => {
 			expect( command.value ).to.be.true;
 		} );
 
-		it( 'has proper value when moved to element that is not a block', () => {
+		it( 'has proper value when inside non-block element', () => {
+			setData( document, '<notBlock>[foo]</notBlock>' );
+
+			expect( command.value ).to.be.false;
+		} );
+
+		it( 'has proper value when moved from block to element that is not a block', () => {
 			setData( document, '<paragraph>[foo]</paragraph><notBlock>foo</notBlock>' );
 			const element = document.getRoot().getChild( 1 );
 
-			expect( command.value ).to.be.true;
-
 			document.enqueueChanges( () => {
 				document.selection.setRanges( [ Range.createIn( element ) ] );
 			} );