diff options
| -rw-r--r-- | background_scripts/completion.coffee | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 9314d9be..c8a06b27 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -50,8 +50,15 @@ class Suggestion highlightTerms: (string) -> ranges = [] for term in @queryTerms - i = string.search(RegexpCache.get(term)) - ranges.push([i, i + term.length]) if i >= 0 + textPosition = 0 + splits = string.split(RegexpCache.get(term, "(", ")")).reverse() + while 0 < splits.length + unmatchedText = splits.pop() + textPosition += unmatchedText.length + matchedText = if 0 < splits.length then splits.pop() else null + if matchedText + ranges.push([textPosition, textPosition + matchedText.length]) + textPosition += matchedText.length return string if ranges.length == 0 |
