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

Commit 5d26bc3

Browse files
authored
Merge pull request #1559 from ckeditor/t/ckeditor5/1265
Fix: `model#deleteContent()` will proper merge elements inside limit element. Closes ckeditor/ckeditor5#1265.
2 parents 72aaaf0 + feb015e commit 5d26bc3

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/model/utils/deletecontent.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ function mergeBranches( writer, startPos, endPos ) {
118118
return;
119119
}
120120

121-
// If one of the positions is a root, then there's nothing more to merge (at least in the current state of implementation).
122-
// Theoretically in this case we could unwrap the <p>: <$root>x[]<p>{}y</p></$root>, but we don't need to support it yet
123-
// so let's just abort.
124-
if ( !startParent.parent || !endParent.parent ) {
121+
// 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.
122+
if ( writer.model.schema.isLimit( startParent ) || writer.model.schema.isLimit( endParent ) ) {
125123
return;
126124
}
127125

tests/model/utils/deletecontent.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ describe( 'DataController utils', () => {
772772
schema.extend( '$block', { allowIn: 'blockLimit' } );
773773

774774
schema.register( 'paragraph', { inheritAllFrom: '$block' } );
775+
schema.register( 'blockQuote', {
776+
allowWhere: '$block',
777+
allowContentOf: '$root'
778+
} );
775779
} );
776780

777781
test(
@@ -804,6 +808,60 @@ describe( 'DataController utils', () => {
804808
'<blockLimit><paragraph>foo [bar</paragraph></blockLimit><blockLimit><paragraph>baz] qux</paragraph></blockLimit>',
805809
'<blockLimit><paragraph>foo []</paragraph></blockLimit><blockLimit><paragraph> qux</paragraph></blockLimit>'
806810
);
811+
812+
// See: https://github.com/ckeditor/ckeditor5/issues/1265.
813+
it( 'should proper merge two elements which are inside limit element', () => {
814+
setData( model,
815+
'<blockLimit>' +
816+
'<blockQuote>' +
817+
'<paragraph>Foo</paragraph>' +
818+
'</blockQuote>' +
819+
'<paragraph>[]Bar</paragraph>' +
820+
'</blockLimit>'
821+
);
822+
823+
model.modifySelection( doc.selection, { direction: 'backward' } );
824+
deleteContent( model, doc.selection );
825+
826+
expect( getData( model ) ).to.equal(
827+
'<blockLimit>' +
828+
'<blockQuote>' +
829+
'<paragraph>Foo[]Bar</paragraph>' +
830+
'</blockQuote>' +
831+
'</blockLimit>' );
832+
} );
833+
834+
it( 'should proper merge elements which are inside limit element (nested elements)', () => {
835+
setData( model,
836+
'<blockQuote>' +
837+
'<blockLimit>' +
838+
'<blockQuote>' +
839+
'<paragraph>Foo.</paragraph>' +
840+
'<blockQuote>' +
841+
'<paragraph>Foo</paragraph>' +
842+
'</blockQuote>' +
843+
'</blockQuote>' +
844+
'<paragraph>[]Bar</paragraph>' +
845+
'</blockLimit>' +
846+
'</blockQuote>'
847+
);
848+
849+
model.modifySelection( doc.selection, { direction: 'backward' } );
850+
deleteContent( model, doc.selection );
851+
852+
expect( getData( model ) ).to.equal(
853+
'<blockQuote>' +
854+
'<blockLimit>' +
855+
'<blockQuote>' +
856+
'<paragraph>Foo.</paragraph>' +
857+
'<blockQuote>' +
858+
'<paragraph>Foo[]Bar</paragraph>' +
859+
'</blockQuote>' +
860+
'</blockQuote>' +
861+
'</blockLimit>' +
862+
'</blockQuote>'
863+
);
864+
} );
807865
} );
808866

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

0 commit comments

Comments
 (0)