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

Autoformat should ignore transparent batches #57

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>' );
} );
} );