Browse Source

Removed ParagraphCommand#title. ParagraphCommand#_doExecute accepts selection instead of element.

Aleksander Nowodzinski 8 years ago
parent
commit
569d5c5ae6

+ 6 - 16
packages/ckeditor5-paragraph/src/paragraphcommand.js

@@ -23,8 +23,6 @@ export default class ParagraphCommand extends Command {
 	constructor( editor ) {
 		super( editor );
 
-		const t = editor.t;
-
 		/**
 		 * Value of the command, indicating whether it is applied in the context
 		 * of current {@link module:engine/model/document~Document#selection selection}.
@@ -35,14 +33,6 @@ export default class ParagraphCommand extends Command {
 		 */
 		this.set( 'value', false );
 
-		/**
-		 * User-readable title of the command, for use in the UI.
-		 *
-		 * @readonly
-		 * @member {String}
-		 */
-		this.title = t( 'Paragraph' );
-
 		// Update current value each time changes are done on document.
 		this.listenTo( editor.document, 'changesDone', () => this._updateValue() );
 	}
@@ -54,11 +44,11 @@ export default class ParagraphCommand extends Command {
 	 * @param {Object} [options] Options for executed command.
 	 * @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps.
 	 * New batch will be created if this option is not set.
-	 * @param {module:engine/model/element~Element} [options.element] Element the command should be applied to.
-	 * By default, if not provided, the command is applied to current {@link module:engine/model/document~Document#selection}.
+	 * @param {module:engine/model/selection~Selection} [options.selection] Selection the command should be applied to.
+	 * By default, if not provided, the command is applied to {@link module:engine/model/document~Document#selection}.
 	 */
 	_doExecute( options = {} ) {
-		if ( this.value && !options.element ) {
+		if ( this.value && !options.selection ) {
 			return;
 		}
 
@@ -66,10 +56,10 @@ export default class ParagraphCommand extends Command {
 
 		document.enqueueChanges( () => {
 			const batch = options.batch || document.batch();
-			const elements = options.element ? [ options.element ] : document.selection.getSelectedBlocks();
+			const blocks = ( options.selection || document.selection ).getSelectedBlocks();
 
-			for ( let element of elements ) {
-				batch.rename( element, 'paragraph' );
+			for ( let block of blocks ) {
+				batch.rename( block, 'paragraph' );
 			}
 		} );
 	}

+ 10 - 11
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -5,6 +5,8 @@
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import ParagraphCommand from '@ckeditor/ckeditor5-paragraph/src/paragraphcommand';
+import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
+import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'HeadingCommand', () => {
@@ -28,12 +30,6 @@ describe( 'HeadingCommand', () => {
 		command.destroy();
 	} );
 
-	describe( 'title', () => {
-		it( 'is set', () => {
-			expect( command.title ).to.equal( 'Paragraph' );
-		} );
-	} );
-
 	describe( 'value', () => {
 		it( 'has default value', () => {
 			setData( document, '' );
@@ -70,13 +66,16 @@ describe( 'HeadingCommand', () => {
 				expect( batch.deltas.length ).to.be.above( 0 );
 			} );
 
-			it( 'should use provided element', () => {
-				setData( document, '<heading1>foo[]bar</heading1><heading1>baz</heading1>' );
+			it( 'should use provided selection', () => {
+				setData( document, '<heading1>foo[]bar</heading1><heading1>baz</heading1><heading1>qux</heading1>' );
 
-				const element = root.getChild( 1 );
+				const secondTolastHeading = root.getChild( 1 );
+				const lastHeading = root.getChild( 2 );
+				const selection = new Selection();
+				selection.addRange( Range.createFromParentsAndOffsets( secondTolastHeading, 0, lastHeading, 0 ) );
 
-				command._doExecute( { element } );
-				expect( getData( document ) ).to.equal( '<heading1>foo[]bar</heading1><paragraph>baz</paragraph>' );
+				command._doExecute( { selection } );
+				expect( getData( document ) ).to.equal( '<heading1>foo[]bar</heading1><paragraph>baz</paragraph><paragraph>qux</paragraph>' );
 			} );
 		} );