Merge "[refactor] Renaming some fields in SearchWidget for clarity"

This commit is contained in:
jenkins-bot 2024-09-09 07:26:57 +00:00 committed by Gerrit Code Review
commit 25b71720a4
4 changed files with 22 additions and 22 deletions

View file

@ -132,35 +132,35 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchIndex = function () {
// remove `mwReference/` prefix
const group = groupName.slice( 12 );
const footnoteNumber = this.docRefs.getIndexLabel( group, listKey );
const citation = ( group ? group + ' ' : '' ) + footnoteNumber;
const footnoteLabel = ( group ? group + ' ' : '' ) + footnoteNumber;
// Use [\s\S]* instead of .* to catch esoteric whitespace (T263698)
const matches = listKey.match( /^literal\/([\s\S]*)$/ );
const name = matches && matches[ 1 ] || '';
let $element;
// Make visible text, citation and reference name searchable
let text = ( citation + ' ' + name ).toLowerCase();
let $refContent;
// Make visible text, footnoteLabel and reference name searchable
let refText = ( footnoteLabel + ' ' + name ).toLowerCase();
const itemNode = groupRefs.getInternalModelNode( listKey );
if ( itemNode.length ) {
$element = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
text = $element.text().toLowerCase() + ' ' + text;
$refContent = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
refText = $refContent.text().toLowerCase() + ' ' + refText;
// Make URLs searchable
$element.find( 'a[href]' ).each( ( k, element ) => {
text += ' ' + element.getAttribute( 'href' );
$refContent.find( 'a[href]' ).each( ( k, element ) => {
refText += ' ' + element.getAttribute( 'href' );
} );
} else {
$element = $( '<span>' )
$refContent = $( '<span>' )
.addClass( 've-ce-mwReferencesListNode-muted' )
.text( ve.msg( 'cite-ve-referenceslist-missingref-in-list' ) );
}
return {
$element: $element,
text: text,
$refContent: $refContent,
searchableText: refText,
// TODO: return a simple node
reference: ve.dm.MWReferenceModel.static.newFromReferenceNode( node ),
citation: citation,
footnoteLabel: footnoteLabel,
name: name
};
} ) );
@ -194,10 +194,10 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchResults = function ( query )
for ( let i = 0; i < this.index.length; i++ ) {
const item = this.index[ i ];
if ( item.text.indexOf( query ) >= 0 ) {
const $citation = $( '<div>' )
.addClass( 've-ui-mwReferenceSearchWidget-citation' )
.text( '[' + item.citation + ']' );
if ( item.searchableText.indexOf( query ) >= 0 ) {
const $footnoteLabel = $( '<div>' )
.addClass( 've-ui-mwReferenceSearchWidget-footnote' )
.text( '[' + item.footnoteLabel + ']' );
const $name = $( '<div>' )
.addClass( 've-ui-mwReferenceSearchWidget-name' )
.toggleClass( 've-ui-mwReferenceSearchWidget-name-autogenerated', /^:\d+$/.test( item.name ) )
@ -205,7 +205,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchResults = function ( query )
items.push(
new ve.ui.MWReferenceResultWidget( {
data: item.reference,
label: $citation.add( $name ).add( item.$element )
label: $footnoteLabel.add( $name ).add( item.$refContent )
} )
);
}

View file

@ -9,7 +9,7 @@
.ve-ui-mwReferenceSearchWidget {
// How the footnote marker appears in the text, e.g. [1]
&-citation {
&-footnote {
float: left;
margin-right: 0.75em;
}

View file

@ -79,7 +79,7 @@ export function getCiteReuseDialogRefResultName( rowNumber ) {
}
export function getCiteReuseDialogRefResultCitation( rowNumber ) {
return cy.get( '.ve-ui-mwReferenceSearchWidget .ve-ui-mwReferenceResultWidget .ve-ui-mwReferenceSearchWidget-citation' )
return cy.get( '.ve-ui-mwReferenceSearchWidget .ve-ui-mwReferenceResultWidget .ve-ui-mwReferenceSearchWidget-footnote' )
.eq( rowNumber - 1 );
}

View file

@ -57,9 +57,9 @@
const index = widget.buildSearchIndex();
assert.deepEqual( index.length, 1 );
assert.deepEqual( index[ 0 ].citation, '1' );
assert.deepEqual( index[ 0 ].footnoteLabel, '1' );
assert.deepEqual( index[ 0 ].name, 'foo' );
assert.deepEqual( index[ 0 ].text, '1 foo' );
assert.deepEqual( index[ 0 ].searchableText, '1 foo' );
} );
QUnit.test( 'isIndexEmpty', ( assert ) => {
@ -73,7 +73,7 @@
QUnit.test( 'buildSearchResults', ( assert ) => {
const widget = new ve.ui.MWReferenceSearchWidget();
widget.index = [ { text: 'a', reference: 'model-a' }, { text: 'b' } ];
widget.index = [ { searchableText: 'a', reference: 'model-a' }, { searchableText: 'b' } ];
assert.strictEqual( widget.getResults().getItemCount(), 0 );
const results = widget.buildSearchResults( 'A' );