diff --git a/content/apply.js b/content/apply.js index 31320aa7..b4ab9ea2 100644 --- a/content/apply.js +++ b/content/apply.js @@ -388,7 +388,7 @@ let sorting = false; let timer; // 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(); return; @@ -396,10 +396,7 @@ function init() { docRootObserver = new MutationObserver(sortStyleElements); 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} = {}) { if (sort && sortStyleMap()) { @@ -434,26 +431,25 @@ } } function sortStyleElements() { - let expected = document.body || document.head; - if (!expected || sorting) { + let prevExpected = document.body || document.head; + if (!prevExpected || sorting) { return; } for (const el of styleElements.values()) { if (!isMovable(el)) { continue; } - let prev = el.previousElementSibling; - while (prev !== expected) { - if (prev && isSkippable(prev)) { - expected = prev; - prev = prev.nextElementSibling; - } else if (!moveAfter(el, expected)) { - return; - } else { + while (true) { + const next = prevExpected.nextElementSibling; + if (next && isSkippable(next)) { + prevExpected = next; + } else if (moveAfter(el, prevExpected)) { + prevExpected = el; break; + } else { + return; } } - expected = el; } if (sorting) { sorting = false; 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