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

Commit

Permalink
Merge a614363 into 900b7d3
Browse files Browse the repository at this point in the history
  • Loading branch information
msamsel committed May 30, 2019
2 parents 900b7d3 + a614363 commit 0630e9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/model/utils/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class Insertion {

// Special case – parent is empty (<p>^</p>).
// We can remove the element after moving insertion position out of it.
if ( parent.isEmpty ) {
if ( parent.isEmpty && parent.parent === allowedIn ) {
this.writer.remove( parent );
}
} else if ( this.position.isAtEnd ) {
Expand Down
37 changes: 37 additions & 0 deletions tests/model/utils/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,43 @@ describe( 'DataController utils', () => {
expect( getData( model ) ).to.equal( '<limit>ab[]foo</limit>' );
expect( stringify( root, affectedRange ) ).to.equal( '<limit>[ab]foo</limit>' );
} );

describe( 'when allowed elements is somewhere above limit', () => {
// $root > table > tableRow > tableCell > paragraph
// After inserting new table ( allowed in root ), empty paragraph shouldn't be removed from current tableCell.
beforeEach( () => {
const schema = model.schema;

schema.register( 'wrapper', {
isLimit: true,
isBlock: true,
isObject: true,
allowWhere: '$block'
} );

schema.extend( 'paragraph', { allowIn: 'limit' } );
schema.extend( 'limit', { allowIn: 'wrapper' } );
} );

it( 'should not remove empty elements when not-allowed element is paste', () => {
setData( model, '<wrapper><limit><paragraph>[]</paragraph></limit></wrapper>' );

// pasted content is forbidden in current selection
const affectedRange = insertHelper( '<wrapper><limit><paragraph>foo</paragraph></limit></wrapper>' );

expect( getData( model ) ).to.equal( '<wrapper><limit>[]<paragraph></paragraph></limit></wrapper>' );
expect( stringify( root, affectedRange ) ).to.equal( '<wrapper><limit><paragraph>[]</paragraph></limit></wrapper>' );
} );

it( 'should correctly paste allowed nodes', () => {
setData( model, '<wrapper><limit><paragraph>[]</paragraph></limit></wrapper>' );

const affectedRange = insertHelper( '<paragraph>foo</paragraph>' );

expect( getData( model ) ).to.equal( '<wrapper><limit><paragraph>foo</paragraph>[]</limit></wrapper>' );
expect( stringify( root, affectedRange ) ).to.equal( '<wrapper><limit>[<paragraph>foo</paragraph>]</limit></wrapper>' );
} );
} );
} );

// Helper function that parses given content and inserts it at the cursor position.
Expand Down

0 comments on commit 0630e9f

Please sign in to comment.