8
0
Pārlūkot izejas kodu

Fix: Autoformat should ignore transparent batches.

Szymon Cofalik 7 gadi atpakaļ
vecāks
revīzija
0a256025c5

+ 5 - 1
packages/ckeditor5-autoformat/src/blockautoformatediting.js

@@ -63,7 +63,11 @@ export default class BlockAutoformatEditing {
 			};
 		}
 
-		editor.model.document.on( 'change', () => {
+		editor.model.document.on( 'change', ( evt, batch ) => {
+			if ( batch.type == 'transparent' ) {
+				return;
+			}
+
 			const changes = Array.from( editor.model.document.differ.getChanges() );
 			const entry = changes[ 0 ];
 

+ 5 - 1
packages/ckeditor5-autoformat/src/inlineautoformatediting.js

@@ -140,7 +140,11 @@ export default class InlineAutoformatEditing {
 			writer.removeSelectionAttribute( attributeKey );
 		} );
 
-		editor.model.document.on( 'change', () => {
+		editor.model.document.on( 'change', ( evt, batch ) => {
+			if ( batch.type == 'transparent' ) {
+				return;
+			}
+
 			const selection = editor.model.document.selection;
 
 			// Do nothing if selection is not collapsed.

+ 12 - 0
packages/ckeditor5-autoformat/tests/blockautoformatediting.js

@@ -94,6 +94,18 @@ describe( 'BlockAutoformatEditing', () => {
 			sinon.assert.notCalled( spy );
 		} );
 	} );
+
+	it( 'should ignore transparent batches', () => {
+		const spy = testUtils.sinon.spy();
+		new BlockAutoformatEditing( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
+
+		setData( model, '<paragraph>*[]</paragraph>' );
+		model.enqueueChange( 'transparent', writer => {
+			writer.insertText( ' ', doc.selection.getFirstPosition() );
+		} );
+
+		sinon.assert.notCalled( spy );
+	} );
 } );
 
 /**

+ 11 - 0
packages/ckeditor5-autoformat/tests/inlineautoformatediting.js

@@ -116,4 +116,15 @@ describe( 'InlineAutoformatEditing', () => {
 			sinon.assert.notCalled( formatSpy );
 		} );
 	} );
+
+	it( 'should ignore transparent batches', () => {
+		new InlineAutoformatEditing( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
+
+		setData( model, '<paragraph>*foobar[]</paragraph>' );
+		model.enqueueChange( 'transparent', writer => {
+			writer.insertText( '*', doc.selection.getFirstPosition() );
+		} );
+
+		expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+	} );
 } );