diff --git a/src/model/utils/deletecontent.js b/src/model/utils/deletecontent.js index 6be972f31..6844b8988 100644 --- a/src/model/utils/deletecontent.js +++ b/src/model/utils/deletecontent.js @@ -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 => { @@ -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' ); diff --git a/tests/model/utils/deletecontent.js b/tests/model/utils/deletecontent.js index 30694c21d..33ee17801 100644 --- a/tests/model/utils/deletecontent.js +++ b/tests/model/utils/deletecontent.js @@ -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();