From b41cc8bca3abe38891fbf9b241ef71b00ad41362 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 1 Dec 2017 05:14:52 +0300 Subject: [PATCH] 4x speed-up of showMatchesOnScrollbar at the cost of a marginally reduced accuracy when line wrapping is enabled, but the difference shouldn't be more than a few pixels, presumably --- edit/match-highlighter-helper.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/edit/match-highlighter-helper.js b/edit/match-highlighter-helper.js index 20576c19..3e453964 100644 --- a/edit/match-highlighter-helper.js +++ b/edit/match-highlighter-helper.js @@ -5,8 +5,10 @@ const HL_APPROVED = 'cm-matchhighlight-approved'; const originalAddOverlay = CodeMirror.prototype.addOverlay; const originalRemoveOverlay = CodeMirror.prototype.removeOverlay; + const originalMatchesOnScrollbar = CodeMirror.prototype.showMatchesOnScrollbar; CodeMirror.prototype.addOverlay = addOverlay; CodeMirror.prototype.removeOverlay = removeOverlay; + CodeMirror.prototype.showMatchesOnScrollbar = matchesOnScrollbar; return; function shouldIntercept(overlay) { @@ -49,6 +51,16 @@ }; overlay.token = tokenHook; } + + if (this.options.lineWrapping) { + const originalGetOption = CodeMirror.prototype.getOption; + CodeMirror.prototype.getOption = function (option) { + return option !== 'lineWrapping' && originalGetOption.apply(this, arguments); + }; + setTimeout(() => { + CodeMirror.prototype.getOption = originalGetOption; + }); + } } function tokenHook(stream) { @@ -117,4 +129,9 @@ this.showMatchesOnScrollbar = helper.showMatchesOnScrollbar; helper.query = query; } + + function matchesOnScrollbar(query, ...args) { + query = new RegExp(/(?:^|[^\w.#\\-])/.source + query.source.slice(2, -2) + /(?:[^\w.#\\-]|$)/.source); + return originalMatchesOnScrollbar.call(this, query, ...args); + } })();