8
0
Просмотр исходного кода

Fixed EmptyElement constructor, removed clone() method. Updated view Element construtor to not use insertChildren method when there is no children passed.

Szymon Kupś 9 лет назад
Родитель
Сommit
5022d6e84b

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

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

+ 2 - 23
packages/ckeditor5-engine/src/view/emptyelement.js

@@ -23,12 +23,8 @@ export default class EmptyElement extends Element {
 	 * @param {String} name Node name.
 	 * @param {Object|Iterable} [attributes] Collection of attributes.
 	 */
-	constructor( name, attributes ) {
-		super( name, attributes );
-
-		if ( arguments.length > 2 ) {
-			throwCannotAdd();
-		}
+	constructor( name, attributes, children ) {
+		super( name, attributes, children );
 
 		/**
 		 * Returns `null` because filler is not needed for EmptyElements.
@@ -39,23 +35,6 @@ export default class EmptyElement extends Element {
 		this.getFillerOffset = getFillerOffset;
 	}
 
-	/**
-	 * Clones provided element. Overrides {@link module:engine/view/element~Element#clone} method, as it's forbidden to pass child
-	 * nodes to EmptyElement's constructor.
-	 *
-	 * @returns {module:engine/view/emptyelement~EmptyElement} Clone of this element.
-	 */
-	clone() {
-		const cloned = new this.constructor( this.name, this._attrs );
-
-		// Classes and styles are cloned separately - this solution is faster than adding them back to attributes and
-		// parse once again in constructor.
-		cloned._classes = new Set( this._classes );
-		cloned._styles = new Map( this._styles );
-
-		return cloned;
-	}
-
 	/**
 	 * 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