A few fix ups for fd49e8d

* Moved getParent and getRoot from ve.dm.Node back to ve.Node
* Fixed use of getElementLength that should have been changed to getOuterLength, but was changed to getLength (oops)

Change-Id: Ibe5b855aef533dcd493f762a8a02c6a11ce6e7de
This commit is contained in:
Trevor Parscal 2012-04-19 16:47:40 -07:00
parent fd49e8df32
commit f081c0932a
5 changed files with 35 additions and 35 deletions

View file

@ -131,14 +131,14 @@ ve.dm.BranchNode.prototype.splice = function( index, howmany ) {
}
args[i].attach( this );
args[i].on( 'update', this.emitUpdate );
diff += args[i].getLength();
diff += args[i].getOuterLength();
}
}
var removals = this.children.splice.apply( this.children, args );
for ( i = 0, length = removals.length; i < length; i++ ) {
removals[i].detach();
removals[i].removeListener( 'update', this.emitUpdate );
diff -= removals[i].getLength();
diff -= removals[i].getOuterLength();
}
this.adjustLength( diff, true );
this.emit.apply( this, ['afterSplice'].concat( args ) );

View file

@ -105,26 +105,6 @@ ve.dm.Node.prototype.getAttribute = function( key ) {
return this.attributes[key];
};
/**
* Gets a reference to this node's parent.
*
* @method
* @returns {ve.Node} Reference to this node's parent
*/
ve.Node.prototype.getParent = function() {
return this.parent;
};
/**
* Gets the root node in the tree this node is currently attached to.
*
* @method
* @returns {ve.Node} Root node
*/
ve.Node.prototype.getRoot = function() {
return this.root;
};
/**
* Sets the root node to this and all of its children.
*
@ -133,7 +113,7 @@ ve.Node.prototype.getRoot = function() {
* @method
* @param {ve.Node} root Node to use as root
*/
ve.Node.prototype.setRoot = function( root ) {
ve.dm.Node.prototype.setRoot = function( root ) {
// TODO events?
this.root = root;
};
@ -145,7 +125,7 @@ ve.Node.prototype.setRoot = function( root ) {
* @param {ve.Node} parent Node to attach to
* @emits attach (parent)
*/
ve.Node.prototype.attach = function( parent ) {
ve.dm.Node.prototype.attach = function( parent ) {
this.emit( 'beforeAttach', parent );
this.parent = parent;
this.setRoot( parent.getRoot() );
@ -158,7 +138,7 @@ ve.Node.prototype.attach = function( parent ) {
* @method
* @emits detach
*/
ve.Node.prototype.detach = function() {
ve.dm.Node.prototype.detach = function() {
this.emit( 'beforeDetach' );
this.parent = null;
this.setRoot( this );

View file

@ -61,6 +61,26 @@ ve.Node.prototype.getType = function() {
return this.type;
};
/**
* Gets a reference to this node's parent.
*
* @method
* @returns {ve.Node} Reference to this node's parent
*/
ve.Node.prototype.getParent = function() {
return this.parent;
};
/**
* Gets the root node in the tree this node is currently attached to.
*
* @method
* @returns {ve.Node} Root node
*/
ve.Node.prototype.getRoot = function() {
return this.root;
};
/* Inheritance */
ve.extendClass( ve.Node, ve.EventEmitter );

View file

@ -51,16 +51,6 @@ test( 'prototype.getAttribute', 2, function() {
strictEqual( node.getAttribute( 'b' ), 2 );
} );
test( 'prototype.getParent', 1, function() {
var node = new ve.dm.NodeStub();
strictEqual( node.getParent(), null );
} );
test( 'prototype.getRoot', 1, function() {
var node = new ve.dm.NodeStub();
strictEqual( node.getRoot(), node );
} );
test( 'prototype.setRoot', 1, function() {
var node1 = new ve.dm.NodeStub(),
node2 = new ve.dm.NodeStub();

View file

@ -31,3 +31,13 @@ test( 'prototype.getType', 1, function() {
var node = new ve.NodeStub();
strictEqual( node.getType(), 'stub' );
} );
test( 'prototype.getParent', 1, function() {
var node = new ve.dm.NodeStub();
strictEqual( node.getParent(), null );
} );
test( 'prototype.getRoot', 1, function() {
var node = new ve.dm.NodeStub();
strictEqual( node.getRoot(), node );
} );