Add rebuild action to DocumentSynchronizer

Change-Id: I379ceef3829026c4b4157e59243b7663b6c7ab2f
This commit is contained in:
Catrope 2012-05-08 17:35:45 -07:00
parent 94697a3241
commit 00950f3a67

View file

@ -72,7 +72,13 @@ ve.dm.DocumentSynchronizer.prototype.pushResize = function( node, adjustment ) {
} ); } );
}; };
// TODO pushRebuild() ve.dm.DocumentSynchronizer.prototype.pushRebuild = function( oldRange, newRange ) {
this.actions.push( {
'type': 'rebuild',
'oldRange': oldRange,
'newRange': newRange
} );
};
ve.dm.DocumentSynchronizer.prototype.annotation = function( action ) { ve.dm.DocumentSynchronizer.prototype.annotation = function( action ) {
// Queue events for all leaf nodes covered by the range // Queue events for all leaf nodes covered by the range
@ -94,7 +100,23 @@ ve.dm.DocumentSynchronizer.prototype.resize = function( action ) {
this.queueEvent( action.node, 'update' ); this.queueEvent( action.node, 'update' );
}; };
// TODO rebuild() ve.dm.DocumentSynchronizer.prototype.rebuild = function( action ) {
// Find the nodes contained by oldRange
var selection = this.document.selectNodes( action.oldRange, 'siblings' );
if ( selection.length == 0 ) {
// WTF? Nothing to rebuild, I guess. Whatever.
return;
}
// TODO index of firstNode in parent should be in the selectNodes result
var firstNode = selection[0].node,
parent = firstNode.getParent(),
index = parent.indexOf( firstNode );
this.document.rebuildNodes( parent, index, selection.length, action.oldRange.from,
action.newRange.getLength()
);
};
ve.dm.DocumentSynchronizer.prototype.queueEvent = function( node, event ) { ve.dm.DocumentSynchronizer.prototype.queueEvent = function( node, event ) {
// Check if this is already queued // Check if this is already queued