Explorar el Código

Fix: Heading dropdown items should never revert the state, apply only. Closes #83.

Aleksander Nowodzinski hace 8 años
padre
commit
4facbfcc7e

+ 1 - 20
packages/ckeditor5-heading/src/headingcommand.js

@@ -8,9 +8,6 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
-
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
-import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import first from '@ckeditor/ckeditor5-utils/src/first';
 
@@ -70,9 +67,6 @@ export default class HeadingCommand extends Command {
 		const editor = this.editor;
 		const document = editor.document;
 
-		// If current option is same as new option - toggle already applied option back to default one.
-		const shouldRemove = this.value;
-
 		document.enqueueChanges( () => {
 			const batch = options.batch || document.batch();
 			const blocks = Array.from( document.selection.getSelectedBlocks() )
@@ -81,20 +75,7 @@ export default class HeadingCommand extends Command {
 				} );
 
 			for ( const block of blocks ) {
-				// When removing applied option.
-				if ( shouldRemove ) {
-					if ( block.is( this.modelElement ) ) {
-						// Apply paragraph to the selection withing that particular block only instead
-						// of working on the entire document selection.
-						const selection = new Selection();
-						selection.addRange( Range.createIn( block ) );
-
-						// Share the batch with the paragraph command.
-						editor.execute( 'paragraph', { selection, batch } );
-					}
-				}
-				// When applying new option.
-				else if ( !block.is( this.modelElement ) ) {
+				if ( !block.is( this.modelElement ) ) {
 					batch.rename( block, this.modelElement );
 				}
 			}

+ 4 - 17
packages/ckeditor5-heading/tests/headingcommand.js

@@ -148,19 +148,6 @@ describe( 'HeadingCommand', () => {
 
 				expect( batch.deltas.length ).to.be.above( 0 );
 			} );
-
-			it( 'should use provided batch (converting to default option)', () => {
-				const batch = editor.document.batch();
-				const command = commands.heading1;
-
-				setData( document, '<heading1>foo[]bar</heading1>' );
-
-				expect( batch.deltas.length ).to.equal( 0 );
-
-				command.execute( { batch } );
-
-				expect( batch.deltas.length ).to.be.above( 0 );
-			} );
 		} );
 
 		describe( 'collapsed selection', () => {
@@ -171,13 +158,13 @@ describe( 'HeadingCommand', () => {
 				convertTo = option;
 			}
 
-			it( 'converts to default option when executed with already applied option', () => {
+			it( 'does nothing when executed with already applied option', () => {
 				const command = commands.heading1;
 
 				setData( document, '<heading1>foo[]bar</heading1>' );
 				command.execute();
 
-				expect( getData( document ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
+				expect( getData( document ) ).to.equal( '<heading1>foo[]bar</heading1>' );
 			} );
 
 			it( 'converts topmost blocks', () => {
@@ -217,12 +204,12 @@ describe( 'HeadingCommand', () => {
 				);
 			} );
 
-			it( 'resets to default value all elements with same option', () => {
+			it( 'does nothing to the elements with same option', () => {
 				setData( document, '<heading1>foo[</heading1><heading1>bar</heading1><heading2>baz</heading2>]' );
 				commands.heading1.execute();
 
 				expect( getData( document ) ).to.equal(
-					'<paragraph>foo[</paragraph><paragraph>bar</paragraph><heading2>baz</heading2>]'
+					'<heading1>foo[</heading1><heading1>bar</heading1><heading1>baz</heading1>]'
 				);
 			} );