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

View file

@ -79,7 +79,7 @@ export function getCiteReuseDialogRefResultName( rowNumber ) {
} }
export function getCiteReuseDialogRefResultCitation( 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 ); .eq( rowNumber - 1 );
} }

View file

@ -57,9 +57,9 @@
const index = widget.buildSearchIndex(); const index = widget.buildSearchIndex();
assert.deepEqual( index.length, 1 ); 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 ].name, 'foo' );
assert.deepEqual( index[ 0 ].text, '1 foo' ); assert.deepEqual( index[ 0 ].searchableText, '1 foo' );
} ); } );
QUnit.test( 'isIndexEmpty', ( assert ) => { QUnit.test( 'isIndexEmpty', ( assert ) => {
@ -73,7 +73,7 @@
QUnit.test( 'buildSearchResults', ( assert ) => { QUnit.test( 'buildSearchResults', ( assert ) => {
const widget = new ve.ui.MWReferenceSearchWidget(); 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 ); assert.strictEqual( widget.getResults().getItemCount(), 0 );
const results = widget.buildSearchResults( 'A' ); const results = widget.buildSearchResults( 'A' );