mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Merge "Try to always limit our document references to the current fragment"
This commit is contained in:
commit
94d78fa268
|
@ -39,16 +39,22 @@ OO.mixinClass( ve.dm.MWDocumentReferences, OO.EventEmitter );
|
||||||
/**
|
/**
|
||||||
* Singleton MWDocumentReferences for a document.
|
* Singleton MWDocumentReferences for a document.
|
||||||
*
|
*
|
||||||
* @param {ve.dm.Document} fragment Source document associated with the
|
* @param {ve.dm.Document} doc Source document associated with the
|
||||||
* singleton, may be a fragment in which case we step up to the original
|
* singleton. May be a fragment in which case we only look at refs included in
|
||||||
* document.
|
* the fragment.
|
||||||
|
*
|
||||||
* @return {ve.dm.MWDocumentReferences} Singleton docRefs
|
* @return {ve.dm.MWDocumentReferences} Singleton docRefs
|
||||||
*/
|
*/
|
||||||
ve.dm.MWDocumentReferences.static.refsForDoc = function ( fragment ) {
|
ve.dm.MWDocumentReferences.static.refsForDoc = function ( doc ) {
|
||||||
const doc = fragment.getOriginalDocument() || fragment;
|
let docRefs;
|
||||||
let docRefs = doc.getStorage( 'document-references-store' );
|
if ( !doc.getOriginalDocument() ) {
|
||||||
|
// Only use cache if we're working with the full document.
|
||||||
|
docRefs = doc.getStorage( 'document-references-store' );
|
||||||
|
}
|
||||||
if ( docRefs === undefined ) {
|
if ( docRefs === undefined ) {
|
||||||
docRefs = new ve.dm.MWDocumentReferences( doc );
|
docRefs = new ve.dm.MWDocumentReferences( doc );
|
||||||
|
}
|
||||||
|
if ( !doc.getOriginalDocument() ) {
|
||||||
doc.setStorage( 'document-references-store', docRefs );
|
doc.setStorage( 'document-references-store', docRefs );
|
||||||
}
|
}
|
||||||
return docRefs;
|
return docRefs;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
QUnit.module( 've.ui.MWUseExistingReferenceCommand (Cite)', ve.test.utils.newMwEnvironment() );
|
QUnit.module( 've.ui.MWUseExistingReferenceCommand (Cite)', ve.test.utils.newMwEnvironment() );
|
||||||
|
|
||||||
function getFragementMock( hasRefs ) {
|
function getFragmentMock( hasRefs ) {
|
||||||
const docRefsMock = {
|
const docRefsMock = {
|
||||||
hasRefs: () => hasRefs
|
hasRefs: () => hasRefs
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,8 @@ function getFragementMock( hasRefs ) {
|
||||||
return {
|
return {
|
||||||
getDocument: () => ( {
|
getDocument: () => ( {
|
||||||
getOriginalDocument: () => undefined,
|
getOriginalDocument: () => undefined,
|
||||||
getStorage: () => docRefsMock
|
getStorage: () => docRefsMock,
|
||||||
|
setStorage: () => undefined
|
||||||
} ),
|
} ),
|
||||||
getSelection: () => ( {
|
getSelection: () => ( {
|
||||||
getName: () => 'linear'
|
getName: () => 'linear'
|
||||||
|
@ -28,6 +29,6 @@ QUnit.test( 'Constructor', ( assert ) => {
|
||||||
QUnit.test( 'isExecutable', ( assert ) => {
|
QUnit.test( 'isExecutable', ( assert ) => {
|
||||||
const command = new ve.ui.MWUseExistingReferenceCommand();
|
const command = new ve.ui.MWUseExistingReferenceCommand();
|
||||||
|
|
||||||
assert.false( command.isExecutable( getFragementMock( false ) ) );
|
assert.false( command.isExecutable( getFragmentMock( false ) ) );
|
||||||
assert.true( command.isExecutable( getFragementMock( true ) ) );
|
assert.true( command.isExecutable( getFragmentMock( true ) ) );
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in a new issue