8
0
Просмотр исходного кода

Merge pull request #67 from ckeditor/t/66

Fix: List model fixer will not be triggered if a change-to-fix is in a `transparent` batch. Closes #
Piotrek Koszuliński 8 лет назад
Родитель
Сommit
99f52c6ef0

+ 4 - 0
packages/ckeditor5-list/src/converters.js

@@ -570,6 +570,10 @@ export function viewToModelPosition( evt, data ) {
  */
 export function modelChangePostFixer( document ) {
 	return ( evt, type, changes, batch ) => {
+		if ( batch.type == 'transparent' ) {
+			return;
+		}
+
 		if ( type == 'remove' ) {
 			// Fix list items after the cut-out range.
 			// This fix is needed if items in model after cut-out range have now wrong indents compared to their previous siblings.

+ 23 - 0
packages/ckeditor5-list/tests/listengine.js

@@ -2638,6 +2638,29 @@ describe( 'ListEngine', () => {
 	} );
 
 	describe( 'post fixer', () => {
+		it( 'should not be triggered if change-to-fix is in a transparent batch', () => {
+			// Note that the same example is also tested below in the insert suite, however in a non-transparent batch.
+			const input =
+				'<listItem indent="0" type="bulleted">a</listItem>' +
+				'[]' +
+				'<listItem indent="1" type="bulleted">b</listItem>';
+
+			const inserted = '<paragraph>x</paragraph>';
+
+			const output =
+				'<listItem indent="0" type="bulleted">a</listItem>' +
+				'<paragraph>x</paragraph>' +
+				'<listItem indent="1" type="bulleted">b</listItem>';
+
+			setModelData( modelDoc, input );
+
+			modelDoc.enqueueChanges( () => {
+				modelDoc.batch( 'transparent' ).insert( modelDoc.selection.getFirstPosition(), parseModel( inserted, modelDoc.schema ) );
+			} );
+
+			expect( getModelData( modelDoc, { withoutSelection: true } ) ).to.equal( output );
+		} );
+
 		describe( 'insert', () => {
 			function test( testName, input, inserted, output ) {
 				it( testName, () => {