From 45c3ad5f9117d95c82d4a8ecb9b55bdd7e76346e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 3 Jul 2017 15:45:15 -0400 Subject: [PATCH] FIX: stop highlighting single l which is used for sorting --- .../discourse/controllers/full-page-search.js.es6 | 8 ++++++++ .../javascripts/discourse/templates/full-page-search.hbs | 2 +- .../discourse/widgets/search-menu-results.js.es6 | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 index 8f9a0edce08..d85760f6325 100644 --- a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 @@ -46,6 +46,14 @@ export default Ember.Controller.extend({ return Em.isEmpty(q); }, + + @computed('q') + highlightQuery(q) { + if (!q) { return; } + // remove l which can be used for sorting + return _.reject(q.split(/\s+/), t => t === 'l').join(' '); + }, + @computed('skip_context', 'context') searchContextEnabled: { get(skip,context){ diff --git a/app/assets/javascripts/discourse/templates/full-page-search.hbs b/app/assets/javascripts/discourse/templates/full-page-search.hbs index bfeab09cfe2..e3962efe12f 100644 --- a/app/assets/javascripts/discourse/templates/full-page-search.hbs +++ b/app/assets/javascripts/discourse/templates/full-page-search.hbs @@ -107,7 +107,7 @@ {{#if result.blurb}} - {{#highlight-text highlight=q}} + {{#highlight-text highlight=highlightQuery}} {{{unbound result.blurb}}} {{/highlight-text}} {{/if}} diff --git a/app/assets/javascripts/discourse/widgets/search-menu-results.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu-results.js.es6 index 1d190fc7c8b..41216e414e4 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu-results.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu-results.js.es6 @@ -13,7 +13,9 @@ class Highlighted extends RawHtml { decorate($html) { if (this.term) { - $html.highlight(this.term.split(/\s+/), { className: 'search-highlight' }); + // special case ignore "l" which is used for magic sorting + const words = _.reject(this.term.split(/\s+/), t => t === 'l'); + $html.highlight(words, { className: 'search-highlight' }); } } }