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
This commit is contained in:
tophf 2017-12-01 05:14:52 +03:00
parent a6fbc9db11
commit b41cc8bca3

View File

@ -5,8 +5,10 @@
const HL_APPROVED = 'cm-matchhighlight-approved'; const HL_APPROVED = 'cm-matchhighlight-approved';
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;
CodeMirror.prototype.addOverlay = addOverlay; CodeMirror.prototype.addOverlay = addOverlay;
CodeMirror.prototype.removeOverlay = removeOverlay; CodeMirror.prototype.removeOverlay = removeOverlay;
CodeMirror.prototype.showMatchesOnScrollbar = matchesOnScrollbar;
return; return;
function shouldIntercept(overlay) { function shouldIntercept(overlay) {
@ -49,6 +51,16 @@
}; };
overlay.token = tokenHook; 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) { function tokenHook(stream) {
@ -117,4 +129,9 @@
this.showMatchesOnScrollbar = helper.showMatchesOnScrollbar; this.showMatchesOnScrollbar = helper.showMatchesOnScrollbar;
helper.query = query; 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);
}
})(); })();