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({
|
export default Ember.Component.extend({
|
||||||
tagName: 'span',
|
tagName: 'span',
|
||||||
|
|
||||||
_highlightOnInsert: function() {
|
_highlightOnInsert: function() {
|
||||||
const term = this.get('highlight');
|
const term = this.get('highlight');
|
||||||
const self = this;
|
highlightText(this.$(), term);
|
||||||
|
|
||||||
if(!_.isEmpty(term)) {
|
|
||||||
self.$().highlight(term.split(/\s+/), {className: 'search-highlight'});
|
|
||||||
}
|
|
||||||
}.observes('highlight').on('didInsertElement')
|
}.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 { createWidget } from 'discourse/widgets/widget';
|
||||||
import { h } from 'virtual-dom';
|
import { h } from 'virtual-dom';
|
||||||
import { iconNode } from 'discourse/helpers/fa-icon-node';
|
import { iconNode } from 'discourse/helpers/fa-icon-node';
|
||||||
|
import highlightText from 'discourse/lib/highlight-text';
|
||||||
|
|
||||||
class Highlighted extends RawHtml {
|
class Highlighted extends RawHtml {
|
||||||
constructor(html, term) {
|
constructor(html, term) {
|
||||||
|
@ -12,11 +13,7 @@ class Highlighted extends RawHtml {
|
||||||
}
|
}
|
||||||
|
|
||||||
decorate($html) {
|
decorate($html) {
|
||||||
if (this.term) {
|
highlightText($html, 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' });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue