match-highlighter-helper: do nothing when disabled
This commit is contained in:
parent
3bf0f7e2f8
commit
edfca7bfed
|
@ -29,27 +29,36 @@
|
||||||
const originalAddOverlay = CodeMirror.prototype.addOverlay;
|
const originalAddOverlay = CodeMirror.prototype.addOverlay;
|
||||||
const originalRemoveOverlay = CodeMirror.prototype.removeOverlay;
|
const originalRemoveOverlay = CodeMirror.prototype.removeOverlay;
|
||||||
const originalMatchesOnScrollbar = CodeMirror.prototype.showMatchesOnScrollbar;
|
const originalMatchesOnScrollbar = CodeMirror.prototype.showMatchesOnScrollbar;
|
||||||
|
const originalSetOption = CodeMirror.prototype.setOption;
|
||||||
let originalGetOption;
|
let originalGetOption;
|
||||||
|
|
||||||
CodeMirror.prototype.addOverlay = addOverlay;
|
CodeMirror.prototype.addOverlay = addOverlay;
|
||||||
CodeMirror.prototype.removeOverlay = removeOverlay;
|
CodeMirror.prototype.removeOverlay = removeOverlay;
|
||||||
CodeMirror.prototype.showMatchesOnScrollbar = matchesOnScrollbar;
|
CodeMirror.prototype.showMatchesOnScrollbar = matchesOnScrollbar;
|
||||||
|
CodeMirror.prototype.setOption = setOption;
|
||||||
|
|
||||||
|
let enabled = Boolean(prefs.get('editor.matchHighlight'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
function setOption(option, value) {
|
||||||
|
enabled = option === 'highlightSelectionMatches' ? value : enabled;
|
||||||
|
return originalSetOption.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
function shouldIntercept(overlay) {
|
function shouldIntercept(overlay) {
|
||||||
const hlState = this.state.matchHighlighter || {};
|
const hlState = this.state.matchHighlighter || {};
|
||||||
return overlay === hlState.overlay && (hlState.options || {}).showToken;
|
return overlay === hlState.overlay && (hlState.options || {}).showToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addOverlay() {
|
function addOverlay() {
|
||||||
return shouldIntercept.apply(this, arguments) &&
|
return enabled && shouldIntercept.apply(this, arguments) &&
|
||||||
addOverlayForHighlighter.apply(this, arguments) ||
|
addOverlayForHighlighter.apply(this, arguments) ||
|
||||||
originalAddOverlay.apply(this, arguments);
|
originalAddOverlay.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeOverlay() {
|
function removeOverlay() {
|
||||||
return shouldIntercept.apply(this, arguments) &&
|
return enabled && shouldIntercept.apply(this, arguments) &&
|
||||||
removeOverlayForHighlighter.apply(this, arguments) ||
|
removeOverlayForHighlighter.apply(this, arguments) ||
|
||||||
originalRemoveOverlay.apply(this, arguments);
|
originalRemoveOverlay.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
@ -181,6 +190,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchesOnScrollbar(query, ...args) {
|
function matchesOnScrollbar(query, ...args) {
|
||||||
|
if (!enabled) {
|
||||||
|
return originalMatchesOnScrollbar.call(this, query, ...args);
|
||||||
|
}
|
||||||
const state = this.state.matchHighlighter;
|
const state = this.state.matchHighlighter;
|
||||||
const helper = state.highlightHelper = state.highlightHelper || {};
|
const helper = state.highlightHelper = state.highlightHelper || {};
|
||||||
// rewrite the \btoken\b regexp so it matches .token and #token and --token
|
// rewrite the \btoken\b regexp so it matches .token and #token and --token
|
||||||
|
|
Loading…
Reference in New Issue
Block a user