From 66967844c43df60918fdd4359d675b4102f8c40f Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 7 Nov 2018 21:36:14 +0800 Subject: [PATCH] Fix: match-highlighter-helper is broken --- edit/edit.css | 8 ++------ edit/match-highlighter-helper.js | 10 +++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/edit/edit.css b/edit/edit.css index 0126e7a3..302df163 100644 --- a/edit/edit.css +++ b/edit/edit.css @@ -364,15 +364,11 @@ input:invalid { .resize-grip-enabled .CodeMirror-scrollbar-filler { bottom: 7px; /* make space for resize-grip */ } -body[data-match-highlight="token"] .cm-matchhighlight-approved .cm-matchhighlight, -body[data-match-highlight="token"] .CodeMirror-selection-highlight-scrollbar { +.cm-matchhighlight-approved .cm-matchhighlight, +.CodeMirror-selection-highlight-scrollbar { animation: fadein-match-highlighter 1s cubic-bezier(.97,.01,.42,.98); animation-fill-mode: both; } -body[data-match-highlight="selection"] .cm-matchhighlight-approved .cm-matchhighlight, -body[data-match-highlight="selection"] .CodeMirror-selection-highlight-scrollbar { - background-color: rgba(1, 151, 193, 0.1); -} @-webkit-keyframes highlight { from { background-color: #ff9; diff --git a/edit/match-highlighter-helper.js b/edit/match-highlighter-helper.js index 8396a7ed..d1cd3d7e 100644 --- a/edit/match-highlighter-helper.js +++ b/edit/match-highlighter-helper.js @@ -158,7 +158,7 @@ const end = ch + queryLen; const string = this.getLine(line); const area = string.slice(start, end); - const i = area.indexOf(query); + const i = matchIndex(area, query); const startInArea = i < 0 ? NaN : i; if (isNaN(startInArea) || start + startInArea > ch || state.options.showToken.test(string[start + startInArea - 1] || '') || @@ -220,4 +220,12 @@ return originalMatchesOnScrollbar.call(this, query, ...args); } } + + function matchIndex(s, needle) { + if (typeof needle === 'string') { + return s.indexOf(needle); + } + const match = s.match(needle); + return match ? match.index + match[1].length : -1; + } })();