From 3e2d060037c4fecf2cc4802123d77aff004006cf Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Sat, 27 Jul 2024 18:54:45 +0200 Subject: [PATCH] References always deal with original document Singleton always steps up to the original document from fragments, to give absolute numbering. Bug: T370874 Change-Id: I0353649289f6c8fe26fa6bdff5d2367b7b575bac --- modules/ve-cite/ve.dm.MWDocumentReferences.js | 7 +++++-- tests/qunit/ve-cite/ve.ui.MWReferenceSearchWidget.test.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/ve-cite/ve.dm.MWDocumentReferences.js b/modules/ve-cite/ve.dm.MWDocumentReferences.js index 713eb2abc..0c6e2fae3 100644 --- a/modules/ve-cite/ve.dm.MWDocumentReferences.js +++ b/modules/ve-cite/ve.dm.MWDocumentReferences.js @@ -34,10 +34,13 @@ OO.mixinClass( ve.dm.MWDocumentReferences, OO.EventEmitter ); /** * Singleton MWDocumentReferences for a document. * - * @param {ve.dm.Document} doc Source document associated with the singleton + * @param {ve.dm.Document} fragment Source document associated with the + * singleton, may be a fragment in which case we step up to the original + * document. * @return {ve.dm.MWDocumentReferences} Singleton docRefs */ -ve.dm.MWDocumentReferences.static.refsForDoc = function ( doc ) { +ve.dm.MWDocumentReferences.static.refsForDoc = function ( fragment ) { + const doc = fragment.getOriginalDocument() || fragment; let docRefs = doc.getStorage( 'document-references-store' ); if ( docRefs === undefined ) { docRefs = new ve.dm.MWDocumentReferences( doc ); diff --git a/tests/qunit/ve-cite/ve.ui.MWReferenceSearchWidget.test.js b/tests/qunit/ve-cite/ve.ui.MWReferenceSearchWidget.test.js index 7b594e72e..f394d6868 100644 --- a/tests/qunit/ve-cite/ve.ui.MWReferenceSearchWidget.test.js +++ b/tests/qunit/ve-cite/ve.ui.MWReferenceSearchWidget.test.js @@ -13,7 +13,8 @@ function getInternalListMock( groups, mockWithNode ) { getItemNode: () => ( node ) }; const docMock = { - getStorage: () => ( refDocMock ) + getStorage: () => ( refDocMock ), + getOriginalDocument: () => ( null ) }; const mockInternalList = { getDocument: () => ( docMock ),