From: Vladimír Vondruš Date: Thu, 18 Jul 2019 15:24:50 +0000 (+0200) Subject: documentation: trim spaces from the right only if nothing is found. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=20e1743f2dfa1696fafd0907f44385e0266845a5;p=blog.git documentation: trim spaces from the right only if nothing is found. With unconditional trimming it was not possible to narrow down results for page titles containing spaces (or subpages, which are separated by double right arrow surrounded by spaces). --- diff --git a/documentation/search.js b/documentation/search.js index 8b8d7828..67e8e703 100644 --- a/documentation/search.js +++ b/documentation/search.js @@ -232,8 +232,10 @@ var Search = { /* Returns the values in UTF-8, but input is in whatever shitty 16bit encoding JS has */ search: function(searchString) { - /* Normalize the search string first, convert to UTF-8 */ - searchString = this.toUtf8(searchString.toLowerCase().trim()); + /* Normalize the search string first, convert to UTF-8 and trim spaces + from the left. From the right they're trimmed only if nothing is + found, see below. */ + searchString = this.toUtf8(searchString.toLowerCase().replace(/^\s+/,'')); /* TODO: maybe i could make use of InputEvent.data and others here */ @@ -277,8 +279,18 @@ var Search = { break; } - /* Character not found, exit */ - if(!found) break; + /* Character not found */ + if(!found) { + /* If we found everything except spaces at the end, pretend the + spaces aren't there. On the other hand, we *do* want to + try searching with the spaces first -- it can narrow down + the result list for page names or show subpages (which are + after a lookahead barrier that's a space). */ + if(!searchString.substr(foundPrefix).trim().length) + searchString = searchString.substr(0, foundPrefix); + + break; + } } /* Save the whole found prefix for next time */ diff --git a/documentation/test/js-test-data/searchdata.b85 b/documentation/test/js-test-data/searchdata.b85 index 1de2e518..1a915d15 100644 --- a/documentation/test/js-test-data/searchdata.b85 +++ b/documentation/test/js-test-data/searchdata.b85 @@ -1 +1 @@ -O+!-w2LOZt004pl003kG000310RR921ONaj009U904M+f4gdgd009&L0BHdL0{{R4AOHX<00ATb04M+fDgXd(00A%n0BHaLHUI!^00BGz06GBy0suk)fI0vHNB{tG00B?{0B-;RRsaBW00CS80Am0FVgLYT0RRO600C|Q04V?gasU7*00DRa0B!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