From e42535b1ff906013dc09f1c4e6fa482c63366d1c Mon Sep 17 00:00:00 2001 From: Eugen Ciur Date: Sun, 28 Aug 2022 09:57:54 +0200 Subject: [PATCH] highlight autocomplete results highlight autocomplete results --- .../search/autocomplete-item/index.hbs | 15 ++++-- .../search_results/document/index.hbs | 4 +- app/modifiers/text_to_dom.js | 49 +++++++++++++++++++ app/styles/search.scss | 7 +++ 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 app/modifiers/text_to_dom.js diff --git a/app/components/search/autocomplete-item/index.hbs b/app/components/search/autocomplete-item/index.hbs index 894dfd0..250cc99 100644 --- a/app/components/search/autocomplete-item/index.hbs +++ b/app/components/search/autocomplete-item/index.hbs @@ -1,5 +1,10 @@ -
  • -
    -
    {{@item.title}}
    -
    {{@item.path}}
    -
  • \ No newline at end of file +
  • +
    +
    +
    {{@item.title}}
    +
    {{@item.path}}
    +
    +
  • +
    +
    diff --git a/app/components/search_results/document/index.hbs b/app/components/search_results/document/index.hbs index 55a8872..2a1bea0 100644 --- a/app/components/search_results/document/index.hbs +++ b/app/components/search_results/document/index.hbs @@ -6,9 +6,7 @@ {{@result_node.title}} - - - \ No newline at end of file + diff --git a/app/modifiers/text_to_dom.js b/app/modifiers/text_to_dom.js new file mode 100644 index 0000000..6641329 --- /dev/null +++ b/app/modifiers/text_to_dom.js @@ -0,0 +1,49 @@ +import Modifier from 'ember-modifier'; + + +export default class TextToDom extends Modifier { + /* + Converts plain text to HTML DOM elements and inserts them + as children to `this.element` + + Autocomplete receives text matching highlights as plain text e.g. + + "This is great match". + + Besides the fact that you cannot style plain text, it is also + rendered with tag. + To fix this problem hightlight text is converted to DOM nodes. + */ + didReceiveArguments() { + + let text = this.args.positional[0], + template, + nodes, + that = this, + em_element, + text_element; + + // inspired from https://stackoverflow.com/a/35385518 + // HTML5's