diff --git a/codemirror-overwrites/addon/search/match-highlighter.js b/codemirror-overwrites/addon/search/match-highlighter.js index a3de4c03..f1b49d92 100644 --- a/codemirror-overwrites/addon/search/match-highlighter.js +++ b/codemirror-overwrites/addon/search/match-highlighter.js @@ -119,16 +119,24 @@ function highlightMatches(cm) { cm.operation(function() { var state = cm.state.matchHighlighter; - removeOverlay(cm); if (!cm.somethingSelected() && state.options.showToken) { var re = state.options.showToken === true ? /[\w$]/ : state.options.showToken; var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start; while (start && re.test(line.charAt(start - 1))) --start; while (end < line.length && re.test(line.charAt(end))) ++end; - if (start < end) - addOverlay(cm, line.slice(start, end), re, state.options.style); + /* STYLUS: hack start */ + const token = line.slice(start, end); + if (token !== state.lastToken) { + state.lastToken = token; + removeOverlay(cm); + if (token) { + addOverlay(cm, token, re, state.options.style); + } + } return; } + removeOverlay(cm); + /* STYLUS: hack end */ var from = cm.getCursor("from"), to = cm.getCursor("to"); if (from.line != to.line) return; if (state.options.wordsOnly && !isWord(cm, from, to)) return;