mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Merge "MWReferenceSearchWidget buildIndex optimisations"
This commit is contained in:
commit
960922cdb0
|
@ -23,6 +23,7 @@ ve.dm.MWReferenceModel = function VeDmMWReferenceModel() {
|
||||||
this.listIndex = null;
|
this.listIndex = null;
|
||||||
this.group = '';
|
this.group = '';
|
||||||
this.doc = null;
|
this.doc = null;
|
||||||
|
this.deferDoc = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Inheritance */
|
/* Inheritance */
|
||||||
|
@ -47,7 +48,10 @@ ve.dm.MWReferenceModel.static.newFromReferenceNode = function ( node ) {
|
||||||
ref.setListGroup( attr.listGroup );
|
ref.setListGroup( attr.listGroup );
|
||||||
ref.setListIndex( attr.listIndex );
|
ref.setListIndex( attr.listIndex );
|
||||||
ref.setGroup( attr.refGroup );
|
ref.setGroup( attr.refGroup );
|
||||||
ref.setDocument( doc.cloneFromRange( internalList.getItemNode( attr.listIndex ).getRange() ) );
|
ref.deferDoc = function () {
|
||||||
|
// cloneFromRange is very expensive, so lazy evaluate it
|
||||||
|
return doc.cloneFromRange( internalList.getItemNode( attr.listIndex ).getRange() );
|
||||||
|
};
|
||||||
|
|
||||||
return ref;
|
return ref;
|
||||||
};
|
};
|
||||||
|
@ -149,7 +153,7 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
|
||||||
itemNodeRange = internalList.getItemNode( this.listIndex ).getRange();
|
itemNodeRange = internalList.getItemNode( this.listIndex ).getRange();
|
||||||
surfaceModel.change( ve.dm.Transaction.newFromRemoval( doc, itemNodeRange, true ) );
|
surfaceModel.change( ve.dm.Transaction.newFromRemoval( doc, itemNodeRange, true ) );
|
||||||
surfaceModel.change(
|
surfaceModel.change(
|
||||||
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, this.doc )
|
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, this.getDocument() )
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -219,6 +223,9 @@ ve.dm.MWReferenceModel.prototype.getGroup = function () {
|
||||||
*/
|
*/
|
||||||
ve.dm.MWReferenceModel.prototype.getDocument = function () {
|
ve.dm.MWReferenceModel.prototype.getDocument = function () {
|
||||||
if ( !this.doc ) {
|
if ( !this.doc ) {
|
||||||
|
if ( this.deferDoc ) {
|
||||||
|
this.doc = this.deferDoc();
|
||||||
|
} else {
|
||||||
this.doc = new ve.dm.Document( [
|
this.doc = new ve.dm.Document( [
|
||||||
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
||||||
{ 'type': '/paragraph' },
|
{ 'type': '/paragraph' },
|
||||||
|
@ -226,6 +233,7 @@ ve.dm.MWReferenceModel.prototype.getDocument = function () {
|
||||||
{ 'type': '/internalList' }
|
{ 'type': '/internalList' }
|
||||||
] );
|
] );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return this.doc;
|
return this.doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function ( internalList ) {
|
||||||
view.$element.find( 'a[href]' ).each( extractAttrs );
|
view.$element.find( 'a[href]' ).each( extractAttrs );
|
||||||
|
|
||||||
this.index.push( {
|
this.index.push( {
|
||||||
'$element': view.$element.clone().show(),
|
'$element': view.$element.clone(),
|
||||||
'text': text,
|
'text': text,
|
||||||
'reference': ref,
|
'reference': ref,
|
||||||
'citation': citation,
|
'citation': citation,
|
||||||
|
|
Loading…
Reference in a new issue