浏览代码

Changed order of the methods in code.

Kamil Piechaczek 7 年之前
父节点
当前提交
7f04655bee

+ 14 - 14
packages/ckeditor5-engine/src/model/element.js

@@ -157,20 +157,6 @@ export default class Element extends Node {
 	}
 
 	/**
-	 * Creates a copy of this element and returns it. Created element has the same name and attributes as the original element.
-	 * If clone is deep, the original element's children are also cloned. If not, then empty element is removed.
-	 *
-	 * @protected
-	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
-	 * element will be cloned without any child.
-	 */
-	_clone( deep = false ) {
-		const children = deep ? Array.from( this._children ).map( node => node._clone( true ) ) : null;
-
-		return new Element( this.name, this.getAttributes(), children );
-	}
-
-	/**
 	 * Returns index of a node that occupies given offset. If given offset is too low, returns `0`. If given offset is
 	 * too high, returns {@link module:engine/model/element~Element#getChildIndex index after last child}.
 	 *
@@ -234,6 +220,20 @@ export default class Element extends Node {
 	}
 
 	/**
+	 * Creates a copy of this element and returns it. Created element has the same name and attributes as the original element.
+	 * If clone is deep, the original element's children are also cloned. If not, then empty element is removed.
+	 *
+	 * @protected
+	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
+	 * element will be cloned without any child.
+	 */
+	_clone( deep = false ) {
+		const children = deep ? Array.from( this._children ).map( node => node._clone( true ) ) : null;
+
+		return new Element( this.name, this.getAttributes(), children );
+	}
+
+	/**
 	 * {@link module:engine/model/element~Element#_insertChildren Inserts} one or more nodes at the end of this element.
 	 *
 	 * @protected

+ 25 - 25
packages/ckeditor5-engine/src/model/node.js

@@ -202,16 +202,6 @@ export default class Node {
 	}
 
 	/**
-	 * Creates a copy of this node, that is a node with exactly same attributes, and returns it.
-	 *
-	 * @protected
-	 * @returns {module:engine/model/node~Node} Node with same attributes as this node.
-	 */
-	_clone() {
-		return new Node( this._attrs );
-	}
-
-	/**
 	 * Gets path to the node. The path is an array containing starting offsets of consecutive ancestors of this node,
 	 * beginning from {@link module:engine/model/node~Node#root root}, down to this node's starting offset. The path can be used to
 	 * create {@link module:engine/model/position~Position Position} instance.
@@ -325,6 +315,31 @@ export default class Node {
 	}
 
 	/**
+	 * Converts `Node` to plain object and returns it.
+	 *
+	 * @returns {Object} `Node` converted to plain object.
+	 */
+	toJSON() {
+		const json = {};
+
+		if ( this._attrs.size ) {
+			json.attributes = [ ...this._attrs ];
+		}
+
+		return json;
+	}
+
+	/**
+	 * Creates a copy of this node, that is a node with exactly same attributes, and returns it.
+	 *
+	 * @protected
+	 * @returns {module:engine/model/node~Node} Node with same attributes as this node.
+	 */
+	_clone() {
+		return new Node( this._attrs );
+	}
+
+	/**
 	 * Removes this node from it's parent.
 	 *
 	 * @protected
@@ -375,21 +390,6 @@ export default class Node {
 	}
 
 	/**
-	 * Converts `Node` to plain object and returns it.
-	 *
-	 * @returns {Object} `Node` converted to plain object.
-	 */
-	toJSON() {
-		const json = {};
-
-		if ( this._attrs.size ) {
-			json.attributes = [ ...this._attrs ];
-		}
-
-		return json;
-	}
-
-	/**
 	 * Checks whether given model tree object is of given type.
 	 *
 	 * This method is useful when processing model tree objects that are of unknown type. For example, a function

+ 10 - 10
packages/ckeditor5-engine/src/model/text.js

@@ -69,16 +69,6 @@ export default class Text extends Node {
 	}
 
 	/**
-	 * Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
-	 *
-	 * @protected
-	 * @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
-	 */
-	_clone() {
-		return new Text( this.data, this.getAttributes() );
-	}
-
-	/**
 	 * Converts `Text` instance to plain object and returns it.
 	 *
 	 * @returns {Object} `Text` instance converted to plain object.
@@ -92,6 +82,16 @@ export default class Text extends Node {
 	}
 
 	/**
+	 * Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
+	 *
+	 * @protected
+	 * @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
+	 */
+	_clone() {
+		return new Text( this.data, this.getAttributes() );
+	}
+
+	/**
 	 * Creates a `Text` instance from given plain object (i.e. parsed JSON string).
 	 *
 	 * @param {Object} json Plain object to be converted to `Text`.

+ 12 - 12
packages/ckeditor5-engine/src/view/attributeelement.js

@@ -73,6 +73,18 @@ export default class AttributeElement extends Element {
 	}
 
 	/**
+	 * Checks if this element is similar to other element.
+	 * Both elements should have the same name, attributes and priority to be considered as similar.
+	 * Two similar elements can contain different set of children nodes.
+	 *
+	 * @param {module:engine/view/element~Element} otherElement
+	 * @returns {Boolean}
+	 */
+	isSimilar( otherElement ) {
+		return super.isSimilar( otherElement ) && this.priority == otherElement.priority;
+	}
+
+	/**
 	 * Clones provided element with priority.
 	 *
 	 * @protected
@@ -88,18 +100,6 @@ export default class AttributeElement extends Element {
 
 		return cloned;
 	}
-
-	/**
-	 * Checks if this element is similar to other element.
-	 * Both elements should have the same name, attributes and priority to be considered as similar.
-	 * Two similar elements can contain different set of children nodes.
-	 *
-	 * @param {module:engine/view/element~Element} otherElement
-	 * @returns {Boolean}
-	 */
-	isSimilar( otherElement ) {
-		return super.isSimilar( otherElement ) && this.priority == otherElement.priority;
-	}
 }
 
 /**

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

@@ -159,42 +159,6 @@ export default class Element extends Node {
 	}
 
 	/**
-	 * Clones provided element.
-	 *
-	 * @protected
-	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
-	 * element will be cloned without any children.
-	 * @returns {module:engine/view/element~Element} Clone of this element.
-	 */
-	_clone( deep = false ) {
-		const childrenClone = [];
-
-		if ( deep ) {
-			for ( const child of this.getChildren() ) {
-				childrenClone.push( child._clone( deep ) );
-			}
-		}
-
-		// ContainerElement and AttributeElement should be also cloned properly.
-		const cloned = new this.constructor( this.name, this._attrs, childrenClone );
-
-		// 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 );
-
-		// Clone custom properties.
-		cloned._customProperties = new Map( this._customProperties );
-
-		// Clone filler offset method.
-		// We can't define this method in a prototype because it's behavior which
-		// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
-		cloned.getFillerOffset = this.getFillerOffset;
-
-		return cloned;
-	}
-
-	/**
 	 * Gets child at the given index.
 	 *
 	 * @param {Number} index Index of child.
@@ -513,6 +477,42 @@ export default class Element extends Node {
 	}
 
 	/**
+	 * Clones provided element.
+	 *
+	 * @protected
+	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
+	 * element will be cloned without any children.
+	 * @returns {module:engine/view/element~Element} Clone of this element.
+	 */
+	_clone( deep = false ) {
+		const childrenClone = [];
+
+		if ( deep ) {
+			for ( const child of this.getChildren() ) {
+				childrenClone.push( child._clone( deep ) );
+			}
+		}
+
+		// ContainerElement and AttributeElement should be also cloned properly.
+		const cloned = new this.constructor( this.name, this._attrs, childrenClone );
+
+		// 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 );
+
+		// Clone custom properties.
+		cloned._customProperties = new Map( this._customProperties );
+
+		// Clone filler offset method.
+		// We can't define this method in a prototype because it's behavior which
+		// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
+		cloned.getFillerOffset = this.getFillerOffset;
+
+		return cloned;
+	}
+
+	/**
 	 * {@link module:engine/view/element~Element#_insertChildren Insert} a child node or a list of child nodes at the end of this node
 	 * and sets the parent of these nodes to this element.
 	 *