Преглед изворни кода

Changed: Removed fixing indent from `IndentCommand`. It is now only post fixer's responsibility.

Szymon Cofalik пре 8 година
родитељ
комит
0cf57fa809

+ 0 - 51
packages/ckeditor5-list/src/indentcommand.js

@@ -90,16 +90,6 @@ export default class IndentCommand extends Command {
 					writer.setAttribute( 'indent', indent, item );
 				}
 			}
-
-			// Check whether some of changed list items' type should not be fixed.
-			// But first, reverse `itemsToChange` again -- we always want to perform those fixes starting from first item (source-wise).
-			if ( this._indentBy < 0 ) {
-				itemsToChange = itemsToChange.reverse();
-			}
-
-			for ( const item of itemsToChange ) {
-				_fixType( item, writer );
-			}
 		} );
 	}
 
@@ -146,44 +136,3 @@ export default class IndentCommand extends Command {
 		return true;
 	}
 }
-
-// Fixes type of `item` element after it was indented/outdented. Looks for a sibling of `item` that has the same
-// indent and sets `item`'s type to the same as that sibling.
-function _fixType( item, writer ) {
-	// Find a preceding sibling of `item` that is a list item of the same list as `item`.
-	const prev = _seekListItem( item, false );
-
-	// If found, fix type.
-	if ( prev ) {
-		writer.setAttribute( 'type', prev.getAttribute( 'type' ), item );
-
-		return;
-	}
-
-	// If not found, find a following sibling of `item` that is a list item of the same list as `item`.
-	const next = _seekListItem( item, true );
-
-	// If found, fix type.
-	if ( next ) {
-		writer.setAttribute( 'type', next.getAttribute( 'type' ), item );
-	}
-}
-
-// Seeks for a list item that has same indent as given `item`. May look through next siblings (`seekForward = true`) or
-// previous siblings (`seekForward = false`). Returns found list item or `null` if item has not been found.
-function _seekListItem( item, seekForward ) {
-	let result = item[ seekForward ? 'nextSibling' : 'previousSibling' ];
-
-	// Look for the previous/next sibling that has same indent and is before a list item element with lower indent.
-	// If elements are split by an element with lower indent, they are on different lists.
-	while ( result && result.is( 'listItem' ) && result.getAttribute( 'indent' ) >= item.getAttribute( 'indent' ) ) {
-		if ( result.getAttribute( 'indent' ) == item.getAttribute( 'indent' ) ) {
-			// We found sibling that is on the same list.
-			return result;
-		}
-
-		result = result[ seekForward ? 'nextSibling' : 'previousSibling' ];
-	}
-
-	return null;
-}

+ 0 - 141
packages/ckeditor5-list/tests/indentcommand.js

@@ -196,49 +196,6 @@ describe( 'IndentCommand', () => {
 					'<listItem indent="0" type="bulleted">g</listItem>'
 				);
 			} );
-
-			it( 'should fix list type when item is intended #1', () => {
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="bulleted">b</listItem>' +
-					'<listItem indent="2" type="numbered">c</listItem>' +
-					'<listItem indent="1" type="bulleted">[]d</listItem>'
-				);
-
-				command.execute();
-
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="bulleted">b</listItem>' +
-					'<listItem indent="2" type="numbered">c</listItem>' +
-					'<listItem indent="2" type="numbered">d</listItem>'
-				);
-			} );
-
-			// Not only boundary list items has to be fixed, but also items in the middle of selection.
-			it( 'should fix list type when item is intended #2', () => {
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">b</listItem>' +
-					'<listItem indent="1" type="numbered">[c</listItem>' +
-					'<listItem indent="0" type="bulleted">d</listItem>' +
-					'<listItem indent="1" type="numbered">e]</listItem>' +
-					'<listItem indent="0" type="bulleted">f</listItem>'
-				);
-
-				command.execute();
-
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">b</listItem>' +
-					'<listItem indent="2" type="numbered">c</listItem>' +
-					'<listItem indent="1" type="numbered">d</listItem>' +
-					'<listItem indent="2" type="numbered">e</listItem>' +
-					'<listItem indent="0" type="bulleted">f</listItem>'
-				);
-			} );
 		} );
 	} );
 
@@ -357,104 +314,6 @@ describe( 'IndentCommand', () => {
 				);
 			} );
 
-			it( 'should fix list type when item is outdented #1', () => {
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="bulleted">b</listItem>' +
-					'<listItem indent="2" type="numbered">[]c</listItem>'
-				);
-
-				command.execute();
-
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="bulleted">b</listItem>' +
-					'<listItem indent="1" type="bulleted">c</listItem>'
-				);
-			} );
-
-			// Look at next siblings if, after outdenting, a list item is a first item in it's list (list item "c").
-			it( 'should fix list type when item is outdented #2', () => {
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">[]b</listItem>' +
-					'<listItem indent="2" type="bulleted">c</listItem>' +
-					'<listItem indent="1" type="numbered">d</listItem>'
-				);
-
-				command.execute();
-
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="0" type="bulleted">b</listItem>' +
-					'<listItem indent="1" type="numbered">c</listItem>' +
-					'<listItem indent="1" type="numbered">d</listItem>'
-				);
-			} );
-
-			// Reported in #53.
-			it( 'should fix list type when item is outdented #3', () => {
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">[b</listItem>' +
-					'<listItem indent="1" type="numbered">c</listItem>' +
-					'<listItem indent="1" type="numbered">d]</listItem>'
-				);
-
-				command.execute();
-
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="0" type="bulleted">b</listItem>' +
-					'<listItem indent="0" type="bulleted">c</listItem>' +
-					'<listItem indent="0" type="bulleted">d</listItem>'
-				);
-			} );
-
-			it( 'should fix list type when item is outdented to top level (if needed)', () => {
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">[]b</listItem>' +
-					'<listItem indent="0" type="numbered">c</listItem>'
-				);
-
-				command.execute();
-
-				// Another possible behaviour would be that "b" list item becomes first list item of a top level
-				// numbered list (so it does not change it's type) but it seems less correct from UX standpoint.
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="0" type="bulleted">b</listItem>' +
-					'<listItem indent="0" type="numbered">c</listItem>'
-				);
-			} );
-
-			it( 'should not fix nested list items\' type when not needed', () => {
-				// There was a bug that the nested sub-list changed it's type because for a while, it was on same indent
-				// level as the originally outdented element.
-				setData(
-					model,
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">b</listItem>' +
-					'<listItem indent="1" type="numbered">[]c</listItem>' +
-					'<listItem indent="2" type="bulleted">d</listItem>' +
-					'<listItem indent="2" type="bulleted">e</listItem>'
-				);
-
-				command.execute();
-
-				expect( getData( model, { withoutSelection: true } ) ).to.equal(
-					'<listItem indent="0" type="bulleted">a</listItem>' +
-					'<listItem indent="1" type="numbered">b</listItem>' +
-					'<listItem indent="0" type="bulleted">c</listItem>' +
-					'<listItem indent="1" type="bulleted">d</listItem>' +
-					'<listItem indent="1" type="bulleted">e</listItem>'
-				);
-			} );
 		} );
 	} );
 } );