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

Commit e42f987

Browse files
authored
Merge pull request #57 from ckeditor/t/56
Fix: Autoformat should ignore transparent batches. Closes #56.
2 parents 29d1a3c + da4212f commit e42f987

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/blockautoformatediting.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export default class BlockAutoformatEditing {
6363
};
6464
}
6565

66-
editor.model.document.on( 'change', () => {
66+
editor.model.document.on( 'change', ( evt, batch ) => {
67+
if ( batch.type == 'transparent' ) {
68+
return;
69+
}
70+
6771
const changes = Array.from( editor.model.document.differ.getChanges() );
6872
const entry = changes[ 0 ];
6973

src/inlineautoformatediting.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ export default class InlineAutoformatEditing {
140140
writer.removeSelectionAttribute( attributeKey );
141141
} );
142142

143-
editor.model.document.on( 'change', () => {
143+
editor.model.document.on( 'change', ( evt, batch ) => {
144+
if ( batch.type == 'transparent' ) {
145+
return;
146+
}
147+
144148
const selection = editor.model.document.selection;
145149

146150
// Do nothing if selection is not collapsed.

tests/blockautoformatediting.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ describe( 'BlockAutoformatEditing', () => {
9494
sinon.assert.notCalled( spy );
9595
} );
9696
} );
97+
98+
it( 'should ignore transparent batches', () => {
99+
const spy = testUtils.sinon.spy();
100+
new BlockAutoformatEditing( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
101+
102+
setData( model, '<paragraph>*[]</paragraph>' );
103+
model.enqueueChange( 'transparent', writer => {
104+
writer.insertText( ' ', doc.selection.getFirstPosition() );
105+
} );
106+
107+
sinon.assert.notCalled( spy );
108+
} );
97109
} );
98110

99111
/**

tests/inlineautoformatediting.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,15 @@ describe( 'InlineAutoformatEditing', () => {
116116
sinon.assert.notCalled( formatSpy );
117117
} );
118118
} );
119+
120+
it( 'should ignore transparent batches', () => {
121+
new InlineAutoformatEditing( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
122+
123+
setData( model, '<paragraph>*foobar[]</paragraph>' );
124+
model.enqueueChange( 'transparent', writer => {
125+
writer.insertText( '*', doc.selection.getFirstPosition() );
126+
} );
127+
128+
expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
129+
} );
119130
} );

0 commit comments

Comments
 (0)