Browse Source

Changed: do not remove "garbage" attributes when turning off list item. They will be removed in post fixer.

Szymon Cofalik 8 years ago
parent
commit
ae84b31f9c

+ 4 - 2
packages/ckeditor5-list/src/listcommand.js

@@ -172,11 +172,13 @@ export default class ListCommand extends Command {
 			// Phew! Now it will be easier :).
 			// For each block element that was in the selection, we will either: turn it to list item,
 			// turn it to paragraph, or change it's type. Or leave it as it is.
-			for ( let element of blocks ) {
+			// Do it in reverse as there might be multiple blocks (same as with changing indents).
+			for ( let element of blocks.reverse() ) {
 				if ( turnOff && element.name == 'listItem' ) {
 					// We are turning off and the element is a `listItem` - it should be converted to `paragraph`.
 					// The order is important to keep model in correct state.
-					batch.rename( element, 'paragraph' ).removeAttribute( element, 'type' ).removeAttribute( element, 'indent' );
+					batch.rename( element, 'paragraph' );
+					// List item specific attributes are removed by post fixer.
 				} else if ( !turnOff && element.name != 'listItem' ) {
 					// We are turning on and the element is not a `listItem` - it should be converted to `listItem`.
 					// The order is important to keep model in correct state.

+ 10 - 9
packages/ckeditor5-list/tests/listcommand.js

@@ -140,12 +140,13 @@ describe( 'ListCommand', () => {
 					expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">fo[]o</listItem>' );
 				} );
 
-				it( 'should rename closest listItem to paragraph and remove attributes', () => {
+				it( 'should rename closest listItem to paragraph', () => {
 					setData( doc, '<listItem indent="0" type="bulleted">fo[]o</listItem>' );
 
 					command._doExecute();
 
-					expect( getData( doc ) ).to.equal( '<paragraph>fo[]o</paragraph>' );
+					// Attributes will be removed by post fixer.
+					expect( getData( doc ) ).to.equal( '<paragraph indent="0" type="bulleted">fo[]o</paragraph>' );
 				} );
 
 				it( 'should change closest listItem\' type', () => {
@@ -216,7 +217,7 @@ describe( 'ListCommand', () => {
 					const expectedData =
 						'<listItem indent="0" type="bulleted">---</listItem>' +
 						'<listItem indent="1" type="bulleted">---</listItem>' +
-						'<paragraph>[]---</paragraph>' +
+						'<paragraph indent="2" type="bulleted">[]---</paragraph>' + // Attributes will be removed by post fixer.
 						'<listItem indent="0" type="bulleted">---</listItem>' +
 						'<listItem indent="1" type="bulleted">---</listItem>' +
 						'<listItem indent="0" type="bulleted">---</listItem>' +
@@ -271,7 +272,7 @@ describe( 'ListCommand', () => {
 					expect( getData( doc ) ).to.equal( expectedData );
 				} );
 
-				it( 'should rename closest listItem to paragraph and remove attributes', () => {
+				it( 'should rename closest listItem to paragraph', () => {
 					// From second bullet list item to first numbered list item.
 					// Command value=true, we are turning off list items.
 					doc.selection.setRanges( [ new Range(
@@ -284,10 +285,10 @@ describe( 'ListCommand', () => {
 
 					const expectedData =
 						'<listItem indent="0" type="bulleted">---</listItem>' +
-						'<paragraph>[---</paragraph>' +
+						'<paragraph indent="0" type="bulleted">[---</paragraph>' + // Attributes will be removed by post fixer.
 						'<paragraph>---</paragraph>' +
 						'<paragraph>---</paragraph>' +
-						'<paragraph>]---</paragraph>' +
+						'<paragraph indent="0" type="numbered">]---</paragraph>' + // Attributes will be removed by post fixer.
 						'<listItem indent="0" type="numbered">---</listItem>' +
 						'<listItem indent="1" type="bulleted">---</listItem>' +
 						'<listItem indent="2" type="bulleted">---</listItem>';
@@ -330,11 +331,11 @@ describe( 'ListCommand', () => {
 
 					const expectedData =
 						'<listItem indent="0" type="bulleted">---</listItem>' +
-						'<paragraph>[---</paragraph>' +
+						'<paragraph indent="0" type="bulleted">[---</paragraph>' + // Attributes will be removed by post fixer.
 						'<paragraph>---</paragraph>' +
 						'<paragraph>---</paragraph>' +
-						'<paragraph>---</paragraph>' +
-						'<paragraph>]---</paragraph>' +
+						'<paragraph indent="0" type="numbered">---</paragraph>' + // Attributes will be removed by post fixer.
+						'<paragraph indent="0" type="numbered">]---</paragraph>' + // Attributes will be removed by post fixer.
 						'<listItem indent="0" type="bulleted">---</listItem>' +
 						'<listItem indent="1" type="bulleted">---</listItem>';