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 #1559 from ckeditor/t/ckeditor5/1265
Browse files Browse the repository at this point in the history
Fix: `model#deleteContent()` will proper merge elements inside limit element. Closes ckeditor/ckeditor5#1265.
  • Loading branch information
Reinmar authored Oct 26, 2018
2 parents 72aaaf0 + feb015e commit 5d26bc3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/model/utils/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <p>: <$root>x[]<p>{}y</p></$root>, 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;
}

Expand Down
58 changes: 58 additions & 0 deletions tests/model/utils/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -804,6 +808,60 @@ describe( 'DataController utils', () => {
'<blockLimit><paragraph>foo [bar</paragraph></blockLimit><blockLimit><paragraph>baz] qux</paragraph></blockLimit>',
'<blockLimit><paragraph>foo []</paragraph></blockLimit><blockLimit><paragraph> qux</paragraph></blockLimit>'
);

// See: https://github.com/ckeditor/ckeditor5/issues/1265.
it( 'should proper merge two elements which are inside limit element', () => {
setData( model,
'<blockLimit>' +
'<blockQuote>' +
'<paragraph>Foo</paragraph>' +
'</blockQuote>' +
'<paragraph>[]Bar</paragraph>' +
'</blockLimit>'
);

model.modifySelection( doc.selection, { direction: 'backward' } );
deleteContent( model, doc.selection );

expect( getData( model ) ).to.equal(
'<blockLimit>' +
'<blockQuote>' +
'<paragraph>Foo[]Bar</paragraph>' +
'</blockQuote>' +
'</blockLimit>' );
} );

it( 'should proper merge elements which are inside limit element (nested elements)', () => {
setData( model,
'<blockQuote>' +
'<blockLimit>' +
'<blockQuote>' +
'<paragraph>Foo.</paragraph>' +
'<blockQuote>' +
'<paragraph>Foo</paragraph>' +
'</blockQuote>' +
'</blockQuote>' +
'<paragraph>[]Bar</paragraph>' +
'</blockLimit>' +
'</blockQuote>'
);

model.modifySelection( doc.selection, { direction: 'backward' } );
deleteContent( model, doc.selection );

expect( getData( model ) ).to.equal(
'<blockQuote>' +
'<blockLimit>' +
'<blockQuote>' +
'<paragraph>Foo.</paragraph>' +
'<blockQuote>' +
'<paragraph>Foo[]Bar</paragraph>' +
'</blockQuote>' +
'</blockQuote>' +
'</blockLimit>' +
'</blockQuote>'
);
} );
} );

describe( 'should leave a paragraph if the entire content was selected', () => {
Expand Down

0 comments on commit 5d26bc3

Please sign in to comment.