Got rid of iteration to get the surface

Also added a safety check to make it easier to spot a regression

Change-Id: I44515c867852f2f726be74161f6b8e466c0933da
This commit is contained in:
Trevor Parscal 2012-06-20 23:20:42 -07:00 committed by Catrope
parent 00c555ebe5
commit 07eb2df53a
2 changed files with 14 additions and 9 deletions

View file

@ -44,6 +44,16 @@ ve.ce.DocumentNode.prototype.getOuterLength = function() {
return this.length;
};
/**
* Gets the surface this document is attached to.
*
* @method
* @returns {ve.ve.Surface} Surface this document is attached to
*/
ve.ce.DocumentNode.prototype.getSurface = function() {
return this.surface;
};
/* Registration */
ve.ce.nodeFactory.register( 'document', ve.ce.DocumentNode );

View file

@ -122,7 +122,10 @@ ve.ce.TextNode.annotationRenderers = {
* @method
*/
ve.ce.TextNode.prototype.onUpdate = function( force ) {
if ( force === true || this.getSurface().render === true ) {
if ( !force && !this.root.getSurface ) {
throw 'Can not update a text node that is not attached to a document';
}
if ( force === true || this.root.getSurface().render === true ) {
var $new = $( $( '<span>' + this.getHtml() + '</span>' ).contents() );
if ( $new.length === 0 ) {
$new = $new.add( document.createTextNode( '' ) );
@ -301,14 +304,6 @@ ve.ce.TextNode.prototype.getHtml = function() {
return out;
};
ve.ce.TextNode.prototype.getSurface = function() {
var view = this;
while( !view.surface ) {
view = view.parent;
}
return view.surface;
};
/* Registration */
ve.ce.nodeFactory.register( 'text', ve.ce.TextNode );