mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
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:
parent
00c555ebe5
commit
07eb2df53a
|
@ -44,6 +44,16 @@ ve.ce.DocumentNode.prototype.getOuterLength = function() {
|
||||||
return this.length;
|
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 */
|
/* Registration */
|
||||||
|
|
||||||
ve.ce.nodeFactory.register( 'document', ve.ce.DocumentNode );
|
ve.ce.nodeFactory.register( 'document', ve.ce.DocumentNode );
|
||||||
|
|
|
@ -122,7 +122,10 @@ ve.ce.TextNode.annotationRenderers = {
|
||||||
* @method
|
* @method
|
||||||
*/
|
*/
|
||||||
ve.ce.TextNode.prototype.onUpdate = function( force ) {
|
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() );
|
var $new = $( $( '<span>' + this.getHtml() + '</span>' ).contents() );
|
||||||
if ( $new.length === 0 ) {
|
if ( $new.length === 0 ) {
|
||||||
$new = $new.add( document.createTextNode( '' ) );
|
$new = $new.add( document.createTextNode( '' ) );
|
||||||
|
@ -301,14 +304,6 @@ ve.ce.TextNode.prototype.getHtml = function() {
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
ve.ce.TextNode.prototype.getSurface = function() {
|
|
||||||
var view = this;
|
|
||||||
while( !view.surface ) {
|
|
||||||
view = view.parent;
|
|
||||||
}
|
|
||||||
return view.surface;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Registration */
|
/* Registration */
|
||||||
|
|
||||||
ve.ce.nodeFactory.register( 'text', ve.ce.TextNode );
|
ve.ce.nodeFactory.register( 'text', ve.ce.TextNode );
|
||||||
|
|
Loading…
Reference in a new issue