Fix bug causing replacement tree sync to adjust the wrong node

The tree sync for content replacements was adjusting the parent of the
text node affected, rather than the text node itself. This was because
it called getNodeFromOffset(), which returns branch nodes. Switched it
to use selectNodes() in leaves mode

Change-Id: I50a9be18151a1b75815ab19b787b16b6be385bf9
This commit is contained in:
Catrope 2012-05-14 21:42:30 -07:00
parent 2008858830
commit 59f74de3b8

View file

@ -254,16 +254,19 @@ ve.dm.TransactionProcessor.prototype.replace = function( op ) {
insert = this.reversed ? op.remove : op.insert, insert = this.reversed ? op.remove : op.insert,
removeHasStructure = ve.dm.Document.containsElementData( remove ), removeHasStructure = ve.dm.Document.containsElementData( remove ),
insertHasStructure = ve.dm.Document.containsElementData( insert ), insertHasStructure = ve.dm.Document.containsElementData( insert ),
node; node, selection;
// Figure out if this is a structural insert or a content insert // Figure out if this is a structural insert or a content insert
if ( !removeHasStructure && !insertHasStructure ) { if ( !removeHasStructure && !insertHasStructure ) {
// Content insert // Content replacement
// Update the linear model // Update the linear model
ve.batchSplice( this.document.data, this.cursor, remove.length, insert ); ve.batchSplice( this.document.data, this.cursor, remove.length, insert );
this.applyAnnotations( this.cursor + insert.length ); this.applyAnnotations( this.cursor + insert.length );
// Get the node containing the replaced content // Get the node containing the replaced content
node = this.document.getNodeFromOffset( this.cursor ); selection = this.document.selectNodes( new ve.Range( this.cursor, this.cursor ),
'leaves'
);
node = selection[0].node;
// Queue a resize for this node // Queue a resize for this node
this.synchronizer.pushResize( node, insert.length - remove.length ); this.synchronizer.pushResize( node, insert.length - remove.length );
// Advance the cursor // Advance the cursor