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 #886 from ckeditor/t/869
Browse files Browse the repository at this point in the history
Fix: Changed insertContent behaviour, so it doesn't clone given nodes. Closes #869.
  • Loading branch information
Piotr Jasiun authored Mar 23, 2017
2 parents 79b42da + afe5aab commit 45f0f33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/controller/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Insertion {
nodes = Array.from( nodes );

for ( let i = 0; i < nodes.length; i++ ) {
const node = nodes[ i ].clone();
const node = nodes[ i ];

this._handleNode( node, {
isFirst: i === 0 && parentContext.isFirst,
Expand Down
20 changes: 20 additions & 0 deletions tests/controller/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import insertContent from '../../src/controller/insertcontent';

import DocumentFragment from '../../src/model/documentfragment';
import Text from '../../src/model/text';
import Element from '../../src/model/element';

import { setData, getData, parse } from '../../src/dev-utils/model';

Expand Down Expand Up @@ -62,6 +63,25 @@ describe( 'DataController', () => {
expect( getData( doc ) ).to.equal( 'xa[]x' );
} );

it( 'should save the reference to the original object', () => {
const doc = new Document();
const dataController = new DataController( doc );
const batch = doc.batch();
const content = new Element( 'image' );

doc.createRoot();

doc.schema.registerItem( 'paragraph', '$block' );
doc.schema.registerItem( 'image', '$inline' );
doc.schema.objects.add( 'image' );

setData( doc, '<paragraph>foo[]</paragraph>' );

insertContent( dataController, content, doc.selection, batch );

expect( doc.getRoot().getChild( 0 ).getChild( 1 ) ).to.equal( content );
} );

describe( 'in simple scenarios', () => {
beforeEach( () => {
doc = new Document();
Expand Down

0 comments on commit 45f0f33

Please sign in to comment.