Browse Source

View EmptyElement will throw if non-empty array or single element is passed.

Szymon Kupś 9 years ago
parent
commit
c39a6474d1

+ 1 - 1
packages/ckeditor5-engine/src/view/element.js

@@ -73,7 +73,7 @@ export default class Element extends Node {
 		 */
 		this._children = [];
 
-		if ( children && ( children instanceof Node || Array.from( children ).length > 0 ) ) {
+		if ( children ) {
 			this.insertChildren( 0, children );
 		}
 

+ 10 - 20
packages/ckeditor5-engine/src/view/emptyelement.js

@@ -9,6 +9,7 @@
 
 import Element from './element';
 import CKEditorError from 'ckeditor5-utils/src/ckeditorerror';
+import Node from './node';
 
 /**
  * EmptyElement class. It is used to represent elements that cannot contain any child nodes.
@@ -36,33 +37,22 @@ export default class EmptyElement extends Element {
 	}
 
 	/**
-	 * Overrides {@link module:engine/view/element~Element#appendChildren} method.
-	 * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-emptyelement-cannot-add` to prevent adding any child nodes
-	 * to EmptyElement.
-	 */
-	appendChildren() {
-		throwCannotAdd();
-	}
-
-	/**
 	 * Overrides {@link module:engine/view/element~Element#insertChildren} method.
 	 * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-emptyelement-cannot-add` to prevent adding any child nodes
 	 * to EmptyElement.
 	 */
-	insertChildren() {
-		throwCannotAdd();
+	insertChildren( index, nodes ) {
+		if ( nodes && ( nodes instanceof Node || Array.from( nodes ).length > 0 ) ) {
+			/**
+			 * Cannot add children to {@link module:engine/view/emptyelement~EmptyElement}.
+			 *
+			 * @error view-emptyelement-cannot-add
+			 */
+			throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
+		}
 	}
 }
 
-function throwCannotAdd() {
-	/**
-	 * Cannot add children to {@link module:engine/view/emptyelement~EmptyElement}.
-	 *
-	 * @error view-emptyelement-cannot-add
-	 */
-	throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
-}
-
 // Returns `null` because block filler is not needed for EmptyElements.
 //
 // @returns {null}