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

Commit 45f0f33

Browse files
author
Piotr Jasiun
authored
Merge pull request #886 from ckeditor/t/869
Fix: Changed insertContent behaviour, so it doesn't clone given nodes. Closes #869.
2 parents 79b42da + afe5aab commit 45f0f33

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/controller/insertcontent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Insertion {
135135
nodes = Array.from( nodes );
136136

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

140140
this._handleNode( node, {
141141
isFirst: i === 0 && parentContext.isFirst,

tests/controller/insertcontent.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import insertContent from '../../src/controller/insertcontent';
99

1010
import DocumentFragment from '../../src/model/documentfragment';
1111
import Text from '../../src/model/text';
12+
import Element from '../../src/model/element';
1213

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

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

66+
it( 'should save the reference to the original object', () => {
67+
const doc = new Document();
68+
const dataController = new DataController( doc );
69+
const batch = doc.batch();
70+
const content = new Element( 'image' );
71+
72+
doc.createRoot();
73+
74+
doc.schema.registerItem( 'paragraph', '$block' );
75+
doc.schema.registerItem( 'image', '$inline' );
76+
doc.schema.objects.add( 'image' );
77+
78+
setData( doc, '<paragraph>foo[]</paragraph>' );
79+
80+
insertContent( dataController, content, doc.selection, batch );
81+
82+
expect( doc.getRoot().getChild( 0 ).getChild( 1 ) ).to.equal( content );
83+
} );
84+
6585
describe( 'in simple scenarios', () => {
6686
beforeEach( () => {
6787
doc = new Document();

0 commit comments

Comments
 (0)