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

Commit 47070b5

Browse files
authored
Merge pull request #1632 from ckeditor/t/1320c
Fix: Prevented `model.Writer` from inserting empty text nodes. Closes #1320.
2 parents 0e0cae6 + 7611aad commit 47070b5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/model/writer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export default class Writer {
159159
insert( item, itemOrPosition, offset = 0 ) {
160160
this._assertWriterUsedCorrectly();
161161

162+
if ( item instanceof Text && item.data == '' ) {
163+
return;
164+
}
165+
162166
const position = Position._createAt( itemOrPosition, offset );
163167

164168
// If item has a parent already.

tests/model/writer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ describe( 'Writer', () => {
158158
expect( Array.from( parent.getChildren() ) ).to.deep.equal( [ child1, child2, child3 ] );
159159
} );
160160

161+
it( 'should do nothing if empty text node is being inserted', () => {
162+
const parent = createDocumentFragment();
163+
164+
model.enqueueChange( batch, writer => {
165+
const text = writer.createText( '' );
166+
167+
writer.insert( text, parent );
168+
} );
169+
170+
expect( parent.childCount ).to.equal( 0 );
171+
} );
172+
161173
it( 'should create proper operation for inserting element', () => {
162174
const parent = createDocumentFragment();
163175
const element = createElement( 'child' );

0 commit comments

Comments
 (0)