This commit is contained in:
derv82 2017-12-04 22:08:52 -08:00
commit 54f6d31146
2 changed files with 26 additions and 18 deletions

View File

@ -388,7 +388,7 @@
let sorting = false; let sorting = false;
let timer; let timer;
// allow any types of elements between ours, except for the following: // allow any types of elements between ours, except for the following:
const ORDERED_TAGS = ['head', 'body', 'style', 'link']; const ORDERED_TAGS = ['head', 'body', 'frameset', 'style', 'link'];
init(); init();
return; return;
@ -396,11 +396,8 @@
function init() { function init() {
docRootObserver = new MutationObserver(sortStyleElements); docRootObserver = new MutationObserver(sortStyleElements);
Object.assign(docRootObserver, {start, stop}); Object.assign(docRootObserver, {start, stop});
if (!chrome.app) {
// compensate for Firefox missing a step when loading the tab in background
setTimeout(sortStyleElements); setTimeout(sortStyleElements);
} }
}
function start({sort = false} = {}) { function start({sort = false} = {}) {
if (sort && sortStyleMap()) { if (sort && sortStyleMap()) {
sortStyleElements(); sortStyleElements();
@ -434,26 +431,25 @@
} }
} }
function sortStyleElements() { function sortStyleElements() {
let expected = document.body || document.head; let prevExpected = document.body || document.head;
if (!expected || sorting) { if (!prevExpected || sorting) {
return; return;
} }
for (const el of styleElements.values()) { for (const el of styleElements.values()) {
if (!isMovable(el)) { if (!isMovable(el)) {
continue; continue;
} }
let prev = el.previousElementSibling; while (true) {
while (prev !== expected) { const next = prevExpected.nextElementSibling;
if (prev && isSkippable(prev)) { if (next && isSkippable(next)) {
expected = prev; prevExpected = next;
prev = prev.nextElementSibling; } else if (moveAfter(el, prevExpected)) {
} else if (!moveAfter(el, expected)) { prevExpected = el;
return;
} else {
break; break;
} else {
return;
} }
} }
expected = el;
} }
if (sorting) { if (sorting) {
sorting = false; sorting = false;

View File

@ -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