diff --git a/src/blockautoformatediting.js b/src/blockautoformatediting.js index 5e8d5e0..ba4dc12 100644 --- a/src/blockautoformatediting.js +++ b/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 ]; diff --git a/src/inlineautoformatediting.js b/src/inlineautoformatediting.js index 9dcb21c..c3edec6 100644 --- a/src/inlineautoformatediting.js +++ b/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. diff --git a/tests/blockautoformatediting.js b/tests/blockautoformatediting.js index 2b743d2..c4785af 100644 --- a/tests/blockautoformatediting.js +++ b/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, '*[]' ); + model.enqueueChange( 'transparent', writer => { + writer.insertText( ' ', doc.selection.getFirstPosition() ); + } ); + + sinon.assert.notCalled( spy ); + } ); } ); /** diff --git a/tests/inlineautoformatediting.js b/tests/inlineautoformatediting.js index b2b8ddf..6145258 100644 --- a/tests/inlineautoformatediting.js +++ b/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, '*foobar[]' ); + model.enqueueChange( 'transparent', writer => { + writer.insertText( '*', doc.selection.getFirstPosition() ); + } ); + + expect( getData( model ) ).to.equal( '*foobar*[]' ); + } ); } );