瀏覽代碼

Change methods order.

Piotr Jasiun 10 年之前
父節點
當前提交
b4f38a0b30

+ 58 - 58
packages/ckeditor5-engine/src/treeview/element.js

@@ -34,61 +34,61 @@ export default class Element extends Node {
 		this._domElement = null;
 	}
 
+	appendChildren( nodes ) {
+		this.insertChildren( this.getChildCount(), nodes );
+	}
+
 	bindDomElement( domElement ) {
 		this._domElement = domElement;
 
 		Element._domToViewMapping.set( domElement, this );
 	}
 
-	getCorespondingDom() {
-		return this._domElement;
-	}
-
-	// Note that created elements will not have coresponding DOM elements created it these did not exist before.
-	static createFromDom( domElement ) {
-		let viewElement = this.getCorespondingView( domElement );
+	cloneDomAttrs( element ) {
+		this.markToSync( 'ATTRIBUTES_NEED_UPDATE' );
 
-		if ( viewElement ) {
-			return viewElement;
+		for ( let i = element.attributes.length - 1; i >= 0; i-- ) {
+			let attr = element.attributes[ i ];
+			this.setAttr( attr.name, attr.value );
 		}
+	}
 
-		if ( domElement instanceof Text ) {
-			return new ViewText( domElement.data );
-		} else {
-			viewElement = new Element( domElement.name );
-			const attrs = domElement.attributes;
-
-			for ( let i = attrs.length - 1; i >= 0; i-- ) {
-				viewElement.setAttr( attrs[ i ].name, attrs[ i ].value );
-			}
-
-			for ( let childView of viewElement.getChildren() ) {
-				domElement.appendChild( this.createFromDom( childView ) );
-			}
+	getChild( index ) {
+		return this._children[ index ];
+	}
 
-			return domElement;
-		}
+	getChildCount() {
+		return this._children.length;
 	}
 
-	// Coresponding elements exists only for rendered elementes.
-	static getCorespondingView( domElement ) {
-		return this._domToViewMapping.get( domElement );
+	getChildIndex( node ) {
+		return this._children.indexOf( node );
 	}
 
 	getChildren() {
 		return this._children[ Symbol.iterator ]();
 	}
 
-	getChild( index ) {
-		return this._children[ index ];
+	getCorespondingDom() {
+		return this._domElement;
 	}
 
-	getChildCount() {
-		return this._children.length;
+	getAttrKeys() {
+		return this._attrs.keys();
 	}
 
-	getChildIndex( node ) {
-		return this._children.indexOf( node );
+	getAttr( key ) {
+		return this._attrs.get( key );
+	}
+
+	hasAttr( key ) {
+		return this._attrs.has( key );
+	}
+
+	setAttr( key, value ) {
+		this.markToSync( 'ATTRIBUTES_NEED_UPDATE' );
+
+		this._attrs.set( key, value );
 	}
 
 	insertChildren( index, nodes ) {
@@ -106,8 +106,10 @@ export default class Element extends Node {
 		}
 	}
 
-	appendChildren( nodes ) {
-		this.insertChildren( this.getChildCount(), nodes );
+	removeAttr( key ) {
+		this.markToSync( 'ATTRIBUTES_NEED_UPDATE' );
+
+		return this._attrs.delete( key );
 	}
 
 	removeChildren( index, number ) {
@@ -120,37 +122,35 @@ export default class Element extends Node {
 		return new this._children.splice( index, number );
 	}
 
-	getAttrKeys() {
-		return this._attrs.keys();
-	}
-
-	getAttr( key ) {
-		return this._attrs.get( key );
-	}
+	// Note that created elements will not have coresponding DOM elements created it these did not exist before.
+	static createFromDom( domElement ) {
+		let viewElement = this.getCorespondingView( domElement );
 
-	hasAttr( key ) {
-		return this._attrs.has( key );
-	}
+		if ( viewElement ) {
+			return viewElement;
+		}
 
-	setAttr( key, value ) {
-		this.markToSync( 'ATTRIBUTES_NEED_UPDATE' );
+		if ( domElement instanceof Text ) {
+			return new ViewText( domElement.data );
+		} else {
+			viewElement = new Element( domElement.name );
+			const attrs = domElement.attributes;
 
-		this._attrs.set( key, value );
-	}
+			for ( let i = attrs.length - 1; i >= 0; i-- ) {
+				viewElement.setAttr( attrs[ i ].name, attrs[ i ].value );
+			}
 
-	cloneDomAttrs( element ) {
-		this.markToSync( 'ATTRIBUTES_NEED_UPDATE' );
+			for ( let childView of viewElement.getChildren() ) {
+				domElement.appendChild( this.createFromDom( childView ) );
+			}
 
-		for ( let i = element.attributes.length - 1; i >= 0; i-- ) {
-			let attr = element.attributes[ i ];
-			this.setAttr( attr.name, attr.value );
+			return domElement;
 		}
 	}
 
-	removeAttr( key ) {
-		this.markToSync( 'ATTRIBUTES_NEED_UPDATE' );
-
-		return this._attrs.delete( key );
+	// Coresponding elements exists only for rendered elementes.
+	static getCorespondingView( domElement ) {
+		return this._domToViewMapping.get( domElement );
 	}
 }
 

+ 18 - 18
packages/ckeditor5-engine/src/treeview/node.js

@@ -12,12 +12,24 @@ export default class Node {
 		this.parent = null;
 	}
 
-	getTreeView() {
+	getIndex() {
+		let pos;
+
 		if ( !this.parent ) {
 			return null;
-		} else {
-			return this.parent.getTreeView();
 		}
+
+		// No parent or child doesn't exist in parent's children.
+		if ( ( pos = this.parent.getChildIndex( this ) ) == -1 ) {
+			/**
+			 * The node's parent does not contain this node. It means that the document tree is corrupted.
+			 *
+			 * @error treeview-node-not-found-in-parent
+			 */
+			throw new CKEditorError( 'treeview-node-not-found-in-parent: The node\'s parent does not contain this node.' );
+		}
+
+		return pos;
 	}
 
 	getNextSibling() {
@@ -32,24 +44,12 @@ export default class Node {
 		return ( index !== null && this.parent.getChild( index - 1 ) ) || null;
 	}
 
-	getIndex() {
-		let pos;
-
+	getTreeView() {
 		if ( !this.parent ) {
 			return null;
+		} else {
+			return this.parent.getTreeView();
 		}
-
-		// No parent or child doesn't exist in parent's children.
-		if ( ( pos = this.parent.getChildIndex( this ) ) == -1 ) {
-			/**
-			 * The node's parent does not contain this node. It means that the document tree is corrupted.
-			 *
-			 * @error treeview-node-not-found-in-parent
-			 */
-			throw new CKEditorError( 'treeview-node-not-found-in-parent: The node\'s parent does not contain this node.' );
-		}
-
-		return pos;
 	}
 
 	markToSync( type ) {

+ 11 - 11
packages/ckeditor5-engine/src/treeview/observer/mutationobserver.js

@@ -23,17 +23,6 @@ export default class MutationObserver extends Observer {
 		};
 	}
 
-	/**
-	 * @method init
-	 * @param {treeView.TreeView}
-	 */
-	init( treeView ) {
-		this.treeView = treeView;
-		this.domRoot = treeView.domRoot;
-
-		this._mutationObserver = new window.MutationObserver( this._onMutations.bind( this ) );
-	}
-
 	/**
 	 * @method attach
 	 */
@@ -48,6 +37,17 @@ export default class MutationObserver extends Observer {
 		this._mutationObserver.disconnect();
 	}
 
+	/**
+	 * @method init
+	 * @param {treeView.TreeView}
+	 */
+	init( treeView ) {
+		this.treeView = treeView;
+		this.domRoot = treeView.domRoot;
+
+		this._mutationObserver = new window.MutationObserver( this._onMutations.bind( this ) );
+	}
+
 	_onMutations( domMutations ) {
 		// Use map and set for deduplication.
 		const mutatedTexts = new Map();

+ 4 - 4
packages/ckeditor5-engine/src/treeview/observer/observer.js

@@ -7,15 +7,15 @@
 
 export default class Observer {
 	/**
-	 * @method init
-	 * @param {treeView.TreeView}
+	 * @method attach
 	 */
 
 	/**
-	 * @method attach
+	 * @method detach
 	 */
 
 	/**
-	 * @method detach
+	 * @method init
+	 * @param {treeView.TreeView}
 	 */
 }

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

@@ -15,16 +15,6 @@ export default class Text extends Node {
 		this._text = text;
 	}
 
-	getText() {
-		return this._text;
-	}
-
-	setText( text ) {
-		this.markToSync( 'TEXT_NEEDS_UPDATE' );
-
-		this._text = text;
-	}
-
 	getCorespondingDom() {
 		const previousSibling = this.getPreviousSibling();
 
@@ -39,6 +29,16 @@ export default class Text extends Node {
 		return null;
 	}
 
+	getText() {
+		return this._text;
+	}
+
+	setText( text ) {
+		this.markToSync( 'TEXT_NEEDS_UPDATE' );
+
+		this._text = text;
+	}
+
 	static getCorespondingView( domText ) {
 		const previousSibling = domText.previousSibling;