Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #57 from ckeditor/t/56
Browse files Browse the repository at this point in the history
Fix: Autoformat should ignore transparent batches. Closes #56.
  • Loading branch information
szymonkups authored Mar 16, 2018
2 parents 29d1a3c + da4212f commit e42f987
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/blockautoformatediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];

Expand Down
6 changes: 5 additions & 1 deletion src/inlineautoformatediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions tests/blockautoformatediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
} );

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/inlineautoformatediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>' );
} );
} );

0 comments on commit e42f987

Please sign in to comment.