-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
highlight autocomplete results
- Loading branch information
Showing
4 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<li {{on "click" this.onClick}}> | ||
<div class="icon {{@item.type}}"></div> | ||
<div class="title">{{@item.title}}</div> | ||
<div class="path text-muted">{{@item.path}}</div> | ||
</li> | ||
<li | ||
{{on "click" this.onClick}}> | ||
<div class="d-flex flex-row"> | ||
<div class="icon {{@item.type}}"></div> | ||
<div class="title">{{@item.title}}</div> | ||
<div class="path text-muted">{{@item.path}}</div> | ||
</div> | ||
</li> | ||
<div class="text-muted px-3 pb-3" {{textToDom @item.highlight}}> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <em>great</em> match". | ||
Besides the fact that you cannot style plain text, it is also | ||
rendered with <em> 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 <template> tag can be used to convinently convert | ||
// text into DOM nodes | ||
template = document.createElement('template'); | ||
template.innerHTML = text; | ||
|
||
// voila! | ||
nodes = template.content.childNodes; | ||
|
||
nodes.forEach(node => { | ||
// is it <em>some match</em> ? | ||
if (node.nodeName == 'EM') { | ||
em_element = document.createElement('em'); | ||
em_element.textContent = node.firstChild.textContent; | ||
that.element.appendChild(em_element); | ||
} else { | ||
// otherwise node is a plain text | ||
text_element = document.createTextNode(node.textContent); | ||
that.element.appendChild(text_element); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters