浏览代码

Enhanced insertContent to accept items.

Maciej Bukowski 8 年之前
父节点
当前提交
b9ba0334c7

+ 10 - 2
packages/ckeditor5-engine/src/controller/insertcontent.js

@@ -24,7 +24,7 @@ import log from '@ckeditor/ckeditor5-utils/src/log';
  *
  * @param {module:engine/controller/datacontroller~DataController} dataController The data controller in context of which the insertion
  * should be performed.
- * @param {module:engine/model/documentfragment~DocumentFragment} content The content to insert.
+ * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
  * @param {module:engine/model/selection~Selection} selection Selection into which the content should be inserted.
  * @param {module:engine/model/batch~Batch} [batch] Batch to which deltas will be added. If not specified, then
  * changes will be added to a new batch.
@@ -42,9 +42,17 @@ export default function insertContent( dataController, content, selection, batch
 
 	const insertion = new Insertion( dataController, batch, selection.anchor );
 
-	insertion.handleNodes( content.getChildren(), {
+	let nodesToInsert;
+
+	if ( content.is( 'documentFragment' ) ) {
 		// The set of children being inserted is the only set in this context
 		// so it's the first and last (it's a hack ;)).
+		nodesToInsert = content.getChildren();
+	} else {
+		nodesToInsert = [ content ];
+	}
+
+	insertion.handleNodes( nodesToInsert, {
 		isFirst: true,
 		isLast: true
 	} );

+ 0 - 4
packages/ckeditor5-engine/tests/controller/insertcontent.js

@@ -612,10 +612,6 @@ describe( 'DataController', () => {
 			} );
 		}
 
-		if ( !( content instanceof DocumentFragment ) ) {
-			content = new DocumentFragment( [ content ] );
-		}
-
 		insertContent( dataController, content, doc.selection );
 	}
 } );