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

Commit

Permalink
Fix: editor.setData() will no longer crash when the data to set con…
Browse files Browse the repository at this point in the history
…tains markers that are already in the editor content.
  • Loading branch information
scofalik committed Jun 10, 2019
1 parent 01ff6e6 commit fec6868
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,14 @@ export default class DataController {
const modelRoot = this.model.document.getRoot( rootName );

writer.remove( writer.createRangeIn( modelRoot ) );
writer.insert( this.parse( newData[ rootName ], modelRoot ), modelRoot, 0 );

const modelDocumentFragment = this.parse( newData[ rootName ], modelRoot );

for ( const markerName of modelDocumentFragment.markers.keys() ) {
this.model.markers._remove( markerName );
}

writer.insert( modelDocumentFragment, modelRoot, 0 );
}
} );
}
Expand Down
18 changes: 18 additions & 0 deletions tests/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ describe( 'DataController', () => {

expect( getData( model, { withoutSelection: true } ) ).to.equal( 'foo' );
} );

// https://github.com/ckeditor/ckeditor5-engine/issues/1721.
it( 'should not throw when setting the data with markers that already exist in the editor', () => {
schema.extend( '$text', { allowIn: '$root' } );

data.set( 'foo' );

downcastHelpers.markerToElement( { model: 'marker', view: 'marker' } );
upcastHelpers.elementToMarker( { view: 'marker', model: 'marker' } );

model.change( writer => {
writer.addMarker( 'marker', { range: writer.createRangeIn( modelDocument.getRoot() ), usingOperation: true } );
} );

expect( () => {
data.set( data.get() );
} ).not.to.throw();
} );
} );

describe( 'get()', () => {
Expand Down

0 comments on commit fec6868

Please sign in to comment.