mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 01:16:30 +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
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
|
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(),
|
surfaceModel = this.surface.getModel(),
|
||||||
// Store the original selection browsers may reset it after
|
// Store the original selection browsers may reset it after
|
||||||
// the first model change.
|
// the first model change.
|
||||||
|
@ -296,15 +296,10 @@ ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
|
||||||
this.ref.refGroup = refGroup;
|
this.ref.refGroup = refGroup;
|
||||||
}
|
}
|
||||||
// Update internal node content
|
// Update internal node content
|
||||||
|
itemNodeRange = internalList.getItemNode( this.ref.listIndex ).getRange();
|
||||||
|
surfaceModel.change( ve.dm.Transaction.newFromRemoval( doc, itemNodeRange, true ) );
|
||||||
surfaceModel.change(
|
surfaceModel.change(
|
||||||
ve.dm.Transaction.newFromRemoval(
|
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, newDoc )
|
||||||
doc, internalList.getItemNode( this.ref.listIndex ).getRange()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
surfaceModel.change(
|
|
||||||
ve.dm.Transaction.newFromDocumentInsertion(
|
|
||||||
doc, internalList.getItemNode( this.ref.listIndex ).getRange().start, newDoc
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,15 +317,9 @@ ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
|
||||||
item = internalList.getItemInsertion( this.ref.listGroup, this.ref.listKey, [] );
|
item = internalList.getItemInsertion( this.ref.listGroup, this.ref.listKey, [] );
|
||||||
surfaceModel.change( item.transaction );
|
surfaceModel.change( item.transaction );
|
||||||
this.ref.listIndex = item.index;
|
this.ref.listIndex = item.index;
|
||||||
|
itemNodeRange = internalList.getItemNode( this.ref.listIndex ).getRange();
|
||||||
surfaceModel.change(
|
surfaceModel.change(
|
||||||
ve.dm.Transaction.newFromRemoval(
|
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, newDoc )
|
||||||
doc, internalList.getItemNode( this.ref.listIndex ), newDoc, true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
surfaceModel.change(
|
|
||||||
ve.dm.Transaction.newFromDocumentInsertion(
|
|
||||||
doc, internalList.getItemNode( this.ref.listIndex ), newDoc
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Add reference at cursor
|
// 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
|
* @returns {ve.dm.Transaction} Transaction that inserts the nodes and updates the internal list
|
||||||
*/
|
*/
|
||||||
ve.dm.Transaction.newFromDocumentInsertion = function ( doc, offset, newDoc, newDocRange ) {
|
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(),
|
listNode = doc.internalList.getListNode(),
|
||||||
listNodeRange = listNode.getRange(),
|
listNodeRange = listNode.getRange(),
|
||||||
newListNode = newDoc.internalList.getListNode(),
|
newListNode = newDoc.internalList.getListNode(),
|
||||||
|
@ -265,18 +266,25 @@ ve.dm.Transaction.newFromDocumentInsertion = function ( doc, offset, newDoc, new
|
||||||
i = 0;
|
i = 0;
|
||||||
// Find item node in doc
|
// Find item node in doc
|
||||||
while (
|
while (
|
||||||
( range = doc.internalList.getItemNode( i ).getRange() ) &&
|
( spliceItemRange = doc.internalList.getItemNode( i ).getRange() ) &&
|
||||||
offset > range.end
|
offset > spliceItemRange.end
|
||||||
) {
|
) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
// Get range from newDoc
|
|
||||||
range = newDoc.internalList.getItemNode( i ).getRange();
|
|
||||||
|
|
||||||
ve.batchSplice( listData, range.start - newListNodeRange.start,
|
if ( newDoc.origDoc === doc ) {
|
||||||
range.end - range.start, data.data );
|
// Get spliceItemRange from newDoc
|
||||||
ve.batchSplice( listMetadata, range.start - newListNodeRange.start,
|
spliceItemRange = newDoc.internalList.getItemNode( i ).getRange();
|
||||||
range.end - range.start, metadata.data );
|
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.pushRetain( listNodeRange.start );
|
||||||
tx.pushReplace( doc, listNodeRange.start, listNodeRange.end - listNodeRange.start,
|
tx.pushReplace( doc, listNodeRange.start, listNodeRange.end - listNodeRange.start,
|
||||||
listData, listMetadata
|
listData, listMetadata
|
||||||
|
|
Loading…
Reference in a new issue