From f7a12d64d4425b8094d2075ed033ad3deb198557 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Mon, 4 Nov 2013 13:10:43 -0600 Subject: [PATCH] Search: Show close matches in both directions alphabetically --- js/search.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/search.js b/js/search.js index e67506f8a..c8b5ec151 100644 --- a/js/search.js +++ b/js/search.js @@ -61,6 +61,8 @@ var bufs = ['','','','']; var topbufIndex = -1; + var nearMatch = (BattleSearchIndex[i].substr(0,query.length) !== query); + if (nearMatch && i) i--; for (var j=0; j<15; j++) { var id = BattleSearchIndex[i+j]; var type = BattleSearchIndexType[i+j]; @@ -68,7 +70,7 @@ if (!id) break; if (id.substr(0,query.length) !== query) { - if (j) break; + if (!(nearMatch && j<=1)) break; matchLength = 0; } if (j === 0 && this.exactMatch) { @@ -76,7 +78,6 @@ } if (!bufs[typeTable[type]]) bufs[typeTable[type]] = '
  • '+typeName[type]+'

  • '; - if (!matchLength) bufs[typeTable[type]] = '
  • No exact match found. The next match alphabetically is:
  • '+bufs[typeTable[type]]; bufs[typeTable[type]] += Search.renderRow(id, type, 0, matchLength + (BattleSearchIndexOffset[i+j][matchLength-1]||'0').charCodeAt(0)-48); } @@ -86,6 +87,8 @@ bufs[topbufIndex] = ''; } + if (nearMatch) topbuf = '
  • No exact match found. The closest matches alphabetically are:
  • '+topbuf; + this.el.innerHTML = ''; return true; };