From 889c2ea011a1fa2c7519df1b6dd7ea30fac7a4f9 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Tue, 9 May 2023 17:08:34 +0200 Subject: [PATCH] Fix empty previews in reference reuse dialog This fixes a minor inconsistency: A reference that comes from a template and is already reused outside of the template is only partially available to VE, and previewed with a warning message because of this: "This reference is defined in a template or other generated block, and for now can only be previewed in source mode." This was missing in the reuse dialog. Note this patch is not meant to make any design decision, but to use the existing design consistently. You can test this with and without the Citoid extension. It works in both cases. Bug: T336372 Change-Id: I962cf111b1882bcd736f1090ca17d2b176495d2f --- .../ve-cite/ve.ui.MWReferenceSearchWidget.js | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js b/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js index 2a326dbab..6ce5f80f2 100644 --- a/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js +++ b/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js @@ -122,8 +122,6 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () { return; } - var text; - this.index = []; var groupNames = Object.keys( groups ).sort(); @@ -146,10 +144,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () { // Only increment counter for real references n++; var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode ); - var view = new ve.ui.MWPreviewElement( - this.internalList.getItemNode( refModel.getListIndex() ), - { useView: true } - ); + var itemNode = this.internalList.getItemNode( refModel.getListIndex() ); var refGroup = refModel.getGroup(); var citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n; @@ -163,16 +158,25 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () { // immediately rendered, but we shouldn't trust that on principle to // account for edge cases. + var $element; // Make visible text, citation and reference name searchable - text = [ view.$element.text().toLowerCase(), citation, name ].join( ' ' ); - // Make URLs searchable - // eslint-disable-next-line no-loop-func - view.$element.find( 'a[href]' ).each( function () { - text += ' ' + this.getAttribute( 'href' ); - } ); + var text = citation + ' ' + name; + if ( itemNode.length ) { + $element = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element; + text = $element.text().toLowerCase() + ' ' + text; + // Make URLs searchable + // eslint-disable-next-line no-loop-func + $element.find( 'a[href]' ).each( function () { + text += ' ' + this.getAttribute( 'href' ); + } ); + } else { + $element = $( '' ) + .addClass( 've-ce-mwReferencesListNode-muted' ) + .text( ve.msg( 'cite-ve-referenceslist-missingref-in-list' ) ); + } this.index.push( { - $element: view.$element, + $element: $element, text: text, reference: refModel, citation: citation,