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 #1707 from ckeditor/t/1706
Browse files Browse the repository at this point in the history
Fix: Model#deleteContent will not throw anymore if the passed selection is in the graveyard root. Closes #1706.
  • Loading branch information
Reinmar committed Mar 28, 2019
2 parents b2a9d86 + a264d2c commit bd875c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/model/utils/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export default function deleteContent( model, selection, options = {} ) {
return;
}

const selRange = selection.getFirstRange();

// If the selection is already removed, don't do anything.
if ( selRange.root.rootName == '$graveyard' ) {
return;
}

const schema = model.schema;

model.change( writer => {
Expand All @@ -71,7 +78,6 @@ export default function deleteContent( model, selection, options = {} ) {
return;
}

const selRange = selection.getFirstRange();
const startPos = selRange.start;
const endPos = LivePosition.fromPosition( selRange.end, 'toNext' );

Expand Down
23 changes: 23 additions & 0 deletions tests/model/utils/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ describe( 'DataController utils', () => {
} );
} );

it( 'should not do anything if the selection is already in graveyard', () => {
model = new Model();
doc = model.document;

const gy = model.document.graveyard;

gy._appendChild( new Element( 'paragraph' ) );

const baseVersion = model.document.baseVersion;

model.change( writer => {
sinon.spy( writer, 'remove' );

const selection = writer.createSelection( writer.createRangeIn( gy ) );

deleteContent( model, selection );

expect( writer.remove.called ).to.be.false;
} );

expect( model.document.baseVersion ).to.equal( baseVersion );
} );

describe( 'in simple scenarios', () => {
beforeEach( () => {
model = new Model();
Expand Down

0 comments on commit bd875c7

Please sign in to comment.