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

Commit

Permalink
Paragraph will not inserted into list items.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Piechaczek committed Feb 1, 2018
1 parent 15d5d65 commit ab40690
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/model/utils/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ class Insertion {
return;
}

const mergeLeft = context.isFirst && ( node.previousSibling instanceof Element ) && this.canMergeWith.has( node.previousSibling );
const mergeRight = context.isLast && ( node.nextSibling instanceof Element ) && this.canMergeWith.has( node.nextSibling );
const mergeLeft = canMergeLeft.call( this );
const mergeRight = canMergeRight.call( this );
const mergePosLeft = LivePosition.createBefore( node );
const mergePosRight = LivePosition.createAfter( node );

Expand Down Expand Up @@ -327,6 +327,24 @@ class Insertion {

mergePosLeft.detach();
mergePosRight.detach();

function canMergeLeft() {
const previousSibling = node.previousSibling;

return context.isFirst &&
( previousSibling instanceof Element ) &&
this.canMergeWith.has( previousSibling ) &&
this.model.schema.checkMerge( previousSibling, node );
}

function canMergeRight() {
const nextSibling = node.nextSibling;

return context.isLast &&
( nextSibling instanceof Element ) &&
this.canMergeWith.has( nextSibling ) &&
this.model.schema.checkMerge( node, nextSibling );
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/model/utils/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,25 @@ describe( 'DataController utils', () => {
'<paragraph>b</paragraph>'
);
} );

it( 'should not merge a paragraph wrapped in blockQuote with lists', () => {
model.schema.register( 'blockQuote', {
allowWhere: '$block',
allowContentOf: '$root',
} );

setData( model, '<listItem>fo[]o</listItem>' );

insertHelper( '<blockQuote><paragraph>xxx</paragraph></blockQuote><heading1>yyy</heading1>' );

expect( getData( model ) ).to.equal(
'<listItem>fo</listItem>' +
'<blockQuote>' +
'<paragraph>xxx</paragraph>' +
'</blockQuote>' +
'<heading1>yyy[]o</heading1>'
);
} );
} );

describe( 'mixed content to block', () => {
Expand Down

0 comments on commit ab40690

Please sign in to comment.