Merge changes I44515c86,Ife902ace,Ia6510de1

* changes:
  Got rid of iteration to get the surface
  Removed attach and detach methods from ve.ce.Node
  Track adjustments in DocumentSynchronizer and apply them to oldRange
This commit is contained in:
Trevor Parscal 2012-06-21 06:41:57 +00:00 committed by Gerrit Code Review
commit c548b3cdba
5 changed files with 25 additions and 38 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( '' ) );
@ -295,14 +298,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 );

View file

@ -177,40 +177,15 @@ ve.ce.Node.getSplitableNode = function( node ) {
ve.log(node);
if ( node.canBeSplit() ) {
splitableNode = node;
return true;
return true;
} else {
return false;
return false;
}
} );
return splitableNode;
};
/**
* Attaches node as a child to another node.
*
* @method
* @param {ve.ce.Node} parent Node to attach to
* @emits attach (parent)
*/
ve.ce.Node.prototype.attach = function( parent ) {
this.parent = parent;
this.emit( 'attach', parent );
};
/**
* Detaches node from its parent.
*
* @method
* @emits detach (parent)
*/
ve.ce.Node.prototype.detach = function() {
var parent = this.parent;
this.parent = null;
this.emit( 'detach', parent );
};
/* Inheritance */
ve.extendClass( ve.ce.Node, ve.Node );

View file

@ -19,6 +19,7 @@ ve.dm.DocumentSynchronizer = function( doc ) {
this.document = doc;
this.actionQueue = [];
this.eventQueue = [];
this.adjustment = 0;
};
/* Static Members */
@ -80,6 +81,7 @@ ve.dm.DocumentSynchronizer.synchronizers.attributeChange = function( action ) {
*/
ve.dm.DocumentSynchronizer.synchronizers.resize = function( action ) {
action.node.adjustLength( action.adjustment );
this.adjustment += action.adjustment;
// no update needed, adjustLength causes an update event on its own
};
@ -94,7 +96,10 @@ ve.dm.DocumentSynchronizer.synchronizers.resize = function( action ) {
*/
ve.dm.DocumentSynchronizer.synchronizers.rebuild = function( action ) {
// Find the nodes contained by oldRange
var selection = this.document.selectNodes( action.oldRange, 'siblings' );
var selection = this.document.selectNodes(
ve.Range.newFromTranslatedRange( action.oldRange, this.adjustment ),
'siblings'
);
if ( selection.length === 0 ) {
// WTF? Nothing to rebuild, I guess. Whatever.
return;
@ -116,6 +121,7 @@ ve.dm.DocumentSynchronizer.synchronizers.rebuild = function( action ) {
this.document.rebuildNodes( parent, index, numNodes, action.oldRange.from,
action.newRange.getLength()
);
this.adjustment += action.newRange.getLength() - action.oldRange.getLength();
};
/* Methods */

View file

@ -174,10 +174,11 @@ ve.Node.prototype.attach = function( parent ) {
* @emits detach
*/
ve.Node.prototype.detach = function() {
var parent = this.parent;
this.parent = null;
this.setRoot( this );
this.setDocument();
this.emit( 'detach' );
this.emit( 'detach', parent );
};
/**