From: Vladimír Vondruš Date: Thu, 18 Jul 2019 15:23:54 +0000 (+0200) Subject: documentation: reuse the saved searched string instead of creating it again. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=2379e72534f54177fca8b9390434939c6d76b9d3;p=blog.git documentation: reuse the saved searched string instead of creating it again. This avoids duplicating the trimming/decoding logic. --- diff --git a/documentation/search.js b/documentation/search.js index 9b94a3c9..8b8d7828 100644 --- a/documentation/search.js +++ b/documentation/search.js @@ -479,12 +479,8 @@ var Search = { return this.escape(name).replace(/[:=]/g, '‎$&').replace(/(\)|>|&|\/)/g, '‎$&‎'); }, - renderResults: /* istanbul ignore next */ function(value, resultsSuggestedTabAutocompletion) { - /* Normalize the value and encode as UTF-8 so the slicing works - properly */ - value = this.toUtf8(value.trim()); - - if(!value.length) { + renderResults: /* istanbul ignore next */ function(resultsSuggestedTabAutocompletion) { + if(!this.searchString.length) { document.getElementById('search-help').style.display = 'block'; document.getElementById('search-results').style.display = 'none'; document.getElementById('search-notfound').style.display = 'none'; @@ -503,16 +499,16 @@ var Search = { let list = ''; for(let i = 0; i != results.length; ++i) { /* Labels + */ - list += '
' + results[i].typeName + '
' + (results[i].flags & 2 ? '
deprecated
' : '') + (results[i].flags & 4 ? '
deleted
' : ''); + list += '
' + results[i].typeName + '
' + (results[i].flags & 2 ? '
deprecated
' : '') + (results[i].flags & 4 ? '
deleted
' : ''); /* Render the alias (cut off from the right) */ if(results[i].alias) { - list += '
' + this.escape(results[i].name.substr(0, results[i].name.length - value.length - results[i].suffixLength)) + '' + this.escape(results[i].name.substr(results[i].name.length - value.length - results[i].suffixLength, value.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)) + ': ' + this.escape(results[i].alias) + ''; + list += '
' + this.escape(results[i].name.substr(0, results[i].name.length - this.searchString.length - results[i].suffixLength)) + '' + this.escape(results[i].name.substr(results[i].name.length - this.searchString.length - results[i].suffixLength, this.searchString.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)) + ': ' + this.escape(results[i].alias) + ''; /* Render the normal thing (cut off from the left, have to escape for RTL) */ } else { - list += '
' + this.escapeForRtl(results[i].name.substr(0, results[i].name.length - value.length - results[i].suffixLength)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - value.length - results[i].suffixLength, value.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)); + list += '
' + this.escapeForRtl(results[i].name.substr(0, results[i].name.length - this.searchString.length - results[i].suffixLength)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - this.searchString.length - results[i].suffixLength, this.searchString.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)); } /* The closing */ @@ -552,8 +548,8 @@ var Search = { let prev = performance.now(); let results = this.search(value); let after = performance.now(); - this.renderResults(value, results); - if(value.trim().length) { + this.renderResults(results); + if(this.searchString.length) { document.getElementById('search-symbolcount').innerHTML = results[0].length + (results[0].length >= this.maxResults ? '+' : '') + " results (" + Math.round((after - prev)*10)/10 + " ms)"; } else