From edfca7bfed72ffa2452ccf17c8e12b6ff1987111 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 5 Dec 2017 07:40:28 +0300 Subject: [PATCH] match-highlighter-helper: do nothing when disabled --- edit/match-highlighter-helper.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/edit/match-highlighter-helper.js b/edit/match-highlighter-helper.js index fd0c18dc..43fe8533 100644 --- a/edit/match-highlighter-helper.js +++ b/edit/match-highlighter-helper.js @@ -29,27 +29,36 @@ const originalAddOverlay = CodeMirror.prototype.addOverlay; const originalRemoveOverlay = CodeMirror.prototype.removeOverlay; const originalMatchesOnScrollbar = CodeMirror.prototype.showMatchesOnScrollbar; + const originalSetOption = CodeMirror.prototype.setOption; let originalGetOption; CodeMirror.prototype.addOverlay = addOverlay; CodeMirror.prototype.removeOverlay = removeOverlay; CodeMirror.prototype.showMatchesOnScrollbar = matchesOnScrollbar; + CodeMirror.prototype.setOption = setOption; + + let enabled = Boolean(prefs.get('editor.matchHighlight')); return; + function setOption(option, value) { + enabled = option === 'highlightSelectionMatches' ? value : enabled; + return originalSetOption.apply(this, arguments); + } + function shouldIntercept(overlay) { const hlState = this.state.matchHighlighter || {}; return overlay === hlState.overlay && (hlState.options || {}).showToken; } function addOverlay() { - return shouldIntercept.apply(this, arguments) && + return enabled && shouldIntercept.apply(this, arguments) && addOverlayForHighlighter.apply(this, arguments) || originalAddOverlay.apply(this, arguments); } function removeOverlay() { - return shouldIntercept.apply(this, arguments) && + return enabled && shouldIntercept.apply(this, arguments) && removeOverlayForHighlighter.apply(this, arguments) || originalRemoveOverlay.apply(this, arguments); } @@ -181,6 +190,9 @@ } function matchesOnScrollbar(query, ...args) { + if (!enabled) { + return originalMatchesOnScrollbar.call(this, query, ...args); + } const state = this.state.matchHighlighter; const helper = state.highlightHelper = state.highlightHelper || {}; // rewrite the \btoken\b regexp so it matches .token and #token and --token