From 066a471346ae543bddfc6b43a78d1c4482a7da2a Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Thu, 6 Mar 2014 12:10:42 -0800 Subject: [PATCH] Make parameter search widget case insensitive Also ignore pipe and bracket characters, since they are not allowed in parameter names. Change-Id: If7378826f103d0b7f8d24edcdc83419879a0c1fe --- .../ui/widgets/ve.ui.MWParameterSearchWidget.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWParameterSearchWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWParameterSearchWidget.js index 0d42c6a022..920253f496 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWParameterSearchWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWParameterSearchWidget.js @@ -96,7 +96,10 @@ ve.ui.MWParameterSearchWidget.prototype.buildIndex = function () { description = spec.getParameterDescription( name ); this.index.push( { - 'text': [ name, label, aliases.join( ' ' ), description ].join( ' ' ), + // Query information + 'text': [ label, description ].join( ' ' ).toLowerCase(), + 'names': [ name ].concat( aliases ).join( '|' ).toLowerCase(), + // Display information 'name': name, 'label': label, 'aliases': aliases, @@ -114,17 +117,19 @@ ve.ui.MWParameterSearchWidget.prototype.buildIndex = function () { * @method */ ve.ui.MWParameterSearchWidget.prototype.addResults = function () { - var i, len, item, + var i, len, item, textMatch, nameMatch, exactMatch = false, - value = this.query.getValue().trim(), + value = this.query.getValue().trim().replace( /[\|\{\}]/g, '' ), query = value.toLowerCase(), items = []; for ( i = 0, len = this.index.length; i < len; i++ ) { item = this.index[i]; - if ( item.text.indexOf( query ) >= 0 ) { + textMatch = item.text.indexOf( query ) >= 0; + nameMatch = item.names.indexOf( query ) >= 0; + if ( textMatch || nameMatch ) { items.push( new ve.ui.MWParameterResultWidget( item, { '$': this.$ } ) ); - if ( item.name === value || ve.indexOf( value, item.aliases ) !== -1 ) { + if ( nameMatch ) { exactMatch = true; } }