diff --git a/src/model/utils/deletecontent.js b/src/model/utils/deletecontent.js index d3a627027..7dfa28579 100644 --- a/src/model/utils/deletecontent.js +++ b/src/model/utils/deletecontent.js @@ -118,10 +118,8 @@ function mergeBranches( writer, startPos, endPos ) { return; } - // If one of the positions is a root, then there's nothing more to merge (at least in the current state of implementation). - // Theoretically in this case we could unwrap the

: <$root>x[]

{}y

, but we don't need to support it yet - // so let's just abort. - if ( !startParent.parent || !endParent.parent ) { + // If one of the positions is a limit element, then there's nothing to merge because we don't want to cross the limit boundaries. + if ( writer.model.schema.isLimit( startParent ) || writer.model.schema.isLimit( endParent ) ) { return; } diff --git a/tests/model/utils/deletecontent.js b/tests/model/utils/deletecontent.js index befef6e58..463d93880 100644 --- a/tests/model/utils/deletecontent.js +++ b/tests/model/utils/deletecontent.js @@ -772,6 +772,10 @@ describe( 'DataController utils', () => { schema.extend( '$block', { allowIn: 'blockLimit' } ); schema.register( 'paragraph', { inheritAllFrom: '$block' } ); + schema.register( 'blockQuote', { + allowWhere: '$block', + allowContentOf: '$root' + } ); } ); test( @@ -804,6 +808,60 @@ describe( 'DataController utils', () => { 'foo [barbaz] qux', 'foo [] qux' ); + + // See: https://github.com/ckeditor/ckeditor5/issues/1265. + it( 'should proper merge two elements which are inside limit element', () => { + setData( model, + '' + + '
' + + 'Foo' + + '
' + + '[]Bar' + + '
' + ); + + model.modifySelection( doc.selection, { direction: 'backward' } ); + deleteContent( model, doc.selection ); + + expect( getData( model ) ).to.equal( + '' + + '
' + + 'Foo[]Bar' + + '
' + + '
' ); + } ); + + it( 'should proper merge elements which are inside limit element (nested elements)', () => { + setData( model, + '
' + + '' + + '
' + + 'Foo.' + + '
' + + 'Foo' + + '
' + + '
' + + '[]Bar' + + '
' + + '
' + ); + + model.modifySelection( doc.selection, { direction: 'backward' } ); + deleteContent( model, doc.selection ); + + expect( getData( model ) ).to.equal( + '
' + + '' + + '
' + + 'Foo.' + + '
' + + 'Foo[]Bar' + + '
' + + '
' + + '
' + + '
' + ); + } ); } ); describe( 'should leave a paragraph if the entire content was selected', () => {