Fix: match-highlighter-helper is broken

This commit is contained in:
eight 2018-11-07 21:36:14 +08:00
parent 4db8a9ea9a
commit 66967844c4
2 changed files with 11 additions and 7 deletions

View File

@ -364,15 +364,11 @@ input:invalid {
.resize-grip-enabled .CodeMirror-scrollbar-filler { .resize-grip-enabled .CodeMirror-scrollbar-filler {
bottom: 7px; /* make space for resize-grip */ bottom: 7px; /* make space for resize-grip */
} }
body[data-match-highlight="token"] .cm-matchhighlight-approved .cm-matchhighlight, .cm-matchhighlight-approved .cm-matchhighlight,
body[data-match-highlight="token"] .CodeMirror-selection-highlight-scrollbar { .CodeMirror-selection-highlight-scrollbar {
animation: fadein-match-highlighter 1s cubic-bezier(.97,.01,.42,.98); animation: fadein-match-highlighter 1s cubic-bezier(.97,.01,.42,.98);
animation-fill-mode: both; 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 { @-webkit-keyframes highlight {
from { from {
background-color: #ff9; background-color: #ff9;

View File

@ -158,7 +158,7 @@
const end = ch + queryLen; const end = ch + queryLen;
const string = this.getLine(line); const string = this.getLine(line);
const area = string.slice(start, end); const area = string.slice(start, end);
const i = area.indexOf(query); const i = matchIndex(area, query);
const startInArea = i < 0 ? NaN : i; const startInArea = i < 0 ? NaN : i;
if (isNaN(startInArea) || start + startInArea > ch || if (isNaN(startInArea) || start + startInArea > ch ||
state.options.showToken.test(string[start + startInArea - 1] || '') || state.options.showToken.test(string[start + startInArea - 1] || '') ||
@ -220,4 +220,12 @@
return originalMatchesOnScrollbar.call(this, query, ...args); 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;
}
})(); })();