mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 08:10:35 +00:00
Merge "Fix JS errors when inserting references"
This commit is contained in:
commit
e223156d06
|
@ -244,7 +244,7 @@ ve.ui.MWReferenceDialog.prototype.setup = function ( data ) {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
|
||||
var i, len, txs, item, newDoc, group, refGroup, listGroup, keyIndex, refNodes,
|
||||
var i, len, txs, item, newDoc, group, refGroup, listGroup, keyIndex, refNodes, itemNodeRange,
|
||||
surfaceModel = this.surface.getModel(),
|
||||
// Store the original selection browsers may reset it after
|
||||
// the first model change.
|
||||
|
@ -296,15 +296,10 @@ ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
|
|||
this.ref.refGroup = refGroup;
|
||||
}
|
||||
// Update internal node content
|
||||
itemNodeRange = internalList.getItemNode( this.ref.listIndex ).getRange();
|
||||
surfaceModel.change( ve.dm.Transaction.newFromRemoval( doc, itemNodeRange, true ) );
|
||||
surfaceModel.change(
|
||||
ve.dm.Transaction.newFromRemoval(
|
||||
doc, internalList.getItemNode( this.ref.listIndex ).getRange()
|
||||
)
|
||||
);
|
||||
surfaceModel.change(
|
||||
ve.dm.Transaction.newFromDocumentInsertion(
|
||||
doc, internalList.getItemNode( this.ref.listIndex ).getRange().start, newDoc
|
||||
)
|
||||
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, newDoc )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -322,15 +317,9 @@ ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
|
|||
item = internalList.getItemInsertion( this.ref.listGroup, this.ref.listKey, [] );
|
||||
surfaceModel.change( item.transaction );
|
||||
this.ref.listIndex = item.index;
|
||||
itemNodeRange = internalList.getItemNode( this.ref.listIndex ).getRange();
|
||||
surfaceModel.change(
|
||||
ve.dm.Transaction.newFromRemoval(
|
||||
doc, internalList.getItemNode( this.ref.listIndex ), newDoc, true
|
||||
)
|
||||
);
|
||||
surfaceModel.change(
|
||||
ve.dm.Transaction.newFromDocumentInsertion(
|
||||
doc, internalList.getItemNode( this.ref.listIndex ), newDoc
|
||||
)
|
||||
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, newDoc )
|
||||
);
|
||||
}
|
||||
// Add reference at cursor
|
||||
|
|
|
@ -167,7 +167,8 @@ ve.dm.Transaction.newFromRemoval = function ( doc, range, removeMetadata ) {
|
|||
* @returns {ve.dm.Transaction} Transaction that inserts the nodes and updates the internal list
|
||||
*/
|
||||
ve.dm.Transaction.newFromDocumentInsertion = function ( doc, offset, newDoc, newDocRange ) {
|
||||
var i, len, merge, data, metadata, listData, listMetadata, oldEndOffset, newEndOffset, tx, insertion, range,
|
||||
var i, len, merge, data, metadata, listData, listMetadata, oldEndOffset, newEndOffset, tx,
|
||||
insertion, spliceItemRange, spliceListNodeRange,
|
||||
listNode = doc.internalList.getListNode(),
|
||||
listNodeRange = listNode.getRange(),
|
||||
newListNode = newDoc.internalList.getListNode(),
|
||||
|
@ -265,18 +266,25 @@ ve.dm.Transaction.newFromDocumentInsertion = function ( doc, offset, newDoc, new
|
|||
i = 0;
|
||||
// Find item node in doc
|
||||
while (
|
||||
( range = doc.internalList.getItemNode( i ).getRange() ) &&
|
||||
offset > range.end
|
||||
( spliceItemRange = doc.internalList.getItemNode( i ).getRange() ) &&
|
||||
offset > spliceItemRange.end
|
||||
) {
|
||||
i++;
|
||||
}
|
||||
// Get range from newDoc
|
||||
range = newDoc.internalList.getItemNode( i ).getRange();
|
||||
|
||||
ve.batchSplice( listData, range.start - newListNodeRange.start,
|
||||
range.end - range.start, data.data );
|
||||
ve.batchSplice( listMetadata, range.start - newListNodeRange.start,
|
||||
range.end - range.start, metadata.data );
|
||||
if ( newDoc.origDoc === doc ) {
|
||||
// Get spliceItemRange from newDoc
|
||||
spliceItemRange = newDoc.internalList.getItemNode( i ).getRange();
|
||||
spliceListNodeRange = newListNodeRange;
|
||||
} else {
|
||||
// Get spliceItemRange from doc; the while loop has already set it
|
||||
spliceListNodeRange = listNodeRange;
|
||||
}
|
||||
ve.batchSplice( listData, spliceItemRange.start - spliceListNodeRange.start,
|
||||
spliceItemRange.end - spliceItemRange.start, data.data );
|
||||
ve.batchSplice( listMetadata, spliceItemRange.start - spliceListNodeRange.start,
|
||||
spliceItemRange.end - spliceItemRange.start, metadata.data );
|
||||
|
||||
tx.pushRetain( listNodeRange.start );
|
||||
tx.pushReplace( doc, listNodeRange.start, listNodeRange.end - listNodeRange.start,
|
||||
listData, listMetadata
|
||||
|
|
Loading…
Reference in a new issue