FIX: only highlight exact word matches in results
- also fixes phrase highlighting
This commit is contained in:
parent
911ffbb98c
commit
0791d740a6
|
@ -1,13 +1,11 @@
|
|||
import highlightText from 'discourse/lib/highlight-text';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: 'span',
|
||||
|
||||
_highlightOnInsert: function() {
|
||||
const term = this.get('highlight');
|
||||
const self = this;
|
||||
|
||||
if(!_.isEmpty(term)) {
|
||||
self.$().highlight(term.split(/\s+/), {className: 'search-highlight'});
|
||||
}
|
||||
highlightText(this.$(), term);
|
||||
}.observes('highlight').on('didInsertElement')
|
||||
|
||||
});
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
export default function($elem, term) {
|
||||
if(!_.isEmpty(term)) {
|
||||
// special case ignore "l" which is used for magic sorting
|
||||
let words = _.reject(term.match(/"[^"]+"|[^\s]+/g), t => t === 'l');
|
||||
words = words.map(w => w.replace(/^"(.*)"$/, "$1"));
|
||||
$elem.highlight(words, {className: 'search-highlight', wordsOnly: true});
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import RawHtml from 'discourse/widgets/raw-html';
|
|||
import { createWidget } from 'discourse/widgets/widget';
|
||||
import { h } from 'virtual-dom';
|
||||
import { iconNode } from 'discourse/helpers/fa-icon-node';
|
||||
import highlightText from 'discourse/lib/highlight-text';
|
||||
|
||||
class Highlighted extends RawHtml {
|
||||
constructor(html, term) {
|
||||
|
@ -12,11 +13,7 @@ class Highlighted extends RawHtml {
|
|||
}
|
||||
|
||||
decorate($html) {
|
||||
if (this.term) {
|
||||
// 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' });
|
||||
}
|
||||
highlightText($html, this.term);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue