From c11c100cbb03d85ac1e797f5deba5a57a3c106ec Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 16:06:57 +0300 Subject: [PATCH 01/26] circumvent the bug with disabling check marks in Chrome 62+ fixes #272 --- background/background.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/background/background.js b/background/background.js index 2dfe2054..4ae24a2b 100644 --- a/background/background.js +++ b/background/background.js @@ -147,9 +147,13 @@ if (chrome.contextMenus) { chrome.contextMenus.create(item, ignoreChromeError); } }; - const toggleCheckmark = (id, checked) => { - chrome.contextMenus.update(id, {checked}, ignoreChromeError); - }; + + // circumvent the bug with disabling check marks in Chrome 62+ + // TODO: replace 1e6 with the actual rev. number when/if the bug is fixed + const toggleCheckmark = CHROME >= 3172 && CHROME <= 1e6 ? + (id => chrome.contextMenus.remove(id, () => createContextMenus([id]) + ignoreChromeError())) : + ((id, checked) => chrome.contextMenus.update(id, {checked}, ignoreChromeError)); + const togglePresence = (id, checked) => { if (checked) { createContextMenus([id]); @@ -157,6 +161,7 @@ if (chrome.contextMenus) { chrome.contextMenus.remove(id, ignoreChromeError); } }; + const keys = Object.keys(contextMenus); prefs.subscribe(keys.filter(id => typeof prefs.readOnlyValues[id] === 'boolean'), toggleCheckmark); prefs.subscribe(keys.filter(id => contextMenus[id].presentIf), togglePresence); From d263bc8e55a4cc643f8aade24d45335e24cb3d33 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 17:11:35 +0300 Subject: [PATCH 02/26] disallow more nav keys in colorpicker hotkey config dialog --- edit/colorpicker-helper.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/edit/colorpicker-helper.js b/edit/colorpicker-helper.js index 7d7cd651..51d95e3b 100644 --- a/edit/colorpicker-helper.js +++ b/edit/colorpicker-helper.js @@ -75,20 +75,33 @@ var initColorpicker = () => { spellcheck: false, value: prefs.get('editor.colorpicker.hotkey'), onkeydown(event) { - const key = CodeMirror.keyName(event); - // ignore: [Shift?] characters, modifiers-only, [Shift?] Esc, Enter, [Shift?] Tab - if (key === 'Enter' || key === 'Esc') { - $('#help-popup .dismiss').onclick(); - return; - } else if (/^(Space|(Shift-)?(Esc|Tab|[!-~])|(Shift-?|Ctrl-?|Alt-?|Cmd-?)*)$/.test(key)) { - this.setCustomValidity('Not allowed'); - } else { - this.setCustomValidity(''); - prefs.set('editor.colorpicker.hotkey', key); - } event.preventDefault(); event.stopPropagation(); + const key = CodeMirror.keyName(event); + switch (key) { + case 'Enter': + if (this.checkValidity()) { + $('#help-popup .dismiss').onclick(); + } + return; + case 'Esc': + $('#help-popup .dismiss').onclick(); + return; + default: + // disallow: [Shift?] characters, modifiers-only, [modifiers?] + Esc, Tab, nav keys + if (!key || new RegExp('^(' + [ + '(Back)?Space', + '(Shift-)?.', // a single character + '(Shift-?|Ctrl-?|Alt-?|Cmd-?){0,2}(|Esc|Tab|(Page)?(Up|Down)|Left|Right|Home|End|Insert|Delete)', + ].join('|') + ')$', 'i').test(key)) { + this.value = key || this.value; + this.setCustomValidity('Not allowed'); + return; + } + } this.value = key; + this.setCustomValidity(''); + prefs.set('editor.colorpicker.hotkey', key); }, oninput() { // fired on pressing "x" to clear the field From 05d1013699142d2de284ddbee55af6a1fd27197c Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 17:17:43 +0300 Subject: [PATCH 03/26] fixup 2e03c9c9: the element should be in DOM before reposition() --- vendor-overwrites/colorpicker/colorpicker.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vendor-overwrites/colorpicker/colorpicker.js b/vendor-overwrites/colorpicker/colorpicker.js index c03e9e7e..511a08dd 100644 --- a/vendor-overwrites/colorpicker/colorpicker.js +++ b/vendor-overwrites/colorpicker/colorpicker.js @@ -197,6 +197,12 @@ $formatChangeButton.title = opt.tooltipForSwitcher || ''; opt.hideDelay = Math.max(0, opt.hideDelay) || 2000; + $root.classList.add(CSS_PREFIX + 'theme-' + + (opt.theme === 'dark' || opt.theme === 'light' ? + opt.theme : + guessTheme())); + document.body.appendChild($root); + if (!isNaN(options.left) && !isNaN(options.top)) { $root.style = ` display: block; @@ -205,12 +211,6 @@ reposition(); } - $root.classList.add(CSS_PREFIX + 'theme-' + - (opt.theme === 'dark' || opt.theme === 'light' ? - opt.theme : - guessTheme())); - document.body.appendChild($root); - shown = true; registerEvents(); From fbd75260927c1325fa66579961e881d6deae55ce Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 18:29:12 +0300 Subject: [PATCH 04/26] usercss: Alt-PgUp/PgDn go to prev/next @-moz-document --- edit/source-editor.js | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/edit/source-editor.js b/edit/source-editor.js index 6aab98c7..b6090e32 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -143,9 +143,8 @@ function createSourceEditor(style) { cm.on('focus', () => hotkeyRerouter.setState(false)); cm.on('blur', () => hotkeyRerouter.setState(true)); - //if (prefs.get('editor.autocompleteOnTyping')) { - // setupAutocomplete(cm); - //} + CodeMirror.commands.prevEditor = cm => nextPrevMozDocument(cm, -1); + CodeMirror.commands.nextEditor = cm => nextPrevMozDocument(cm, 1); } function updateMeta() { @@ -277,6 +276,47 @@ function createSourceEditor(style) { return dirty.isDirty() || hadBeenSaved; } + function nextPrevMozDocument(cm, dir) { + const cursor = cm.getCursor(); + let line = cursor.line; + let found; + if (dir > 0) { + cm.doc.iter(cursor.line + 1, cm.doc.size, ({text}) => ++line && goFind(text)); + if (!found && cursor.line > 0) { + line = -1; + cm.doc.iter(0, cursor.line, ({text}) => ++line && goFind(text)); + } + } else { + let handle, parentLines; + let passesRemain = line < cm.doc.size - 1 ? 2 : 1; + while (passesRemain--) { + let indexInParent = 0; + while (line--) { + if (!indexInParent--) { + handle = cm.getLineHandle(line); + parentLines = handle.parent.lines; + indexInParent = parentLines.indexOf(handle); + } else { + handle = parentLines[indexInParent]; + } + if (goFind(handle.text)) { + return true; + } + } + line = cm.doc.size; + } + } + function goFind(text) { + const ch = text.indexOf('@-moz-document'); + if (ch >= 0 && cm.getTokenTypeAt({line, ch}) === 'def') { + cm.scrollIntoView({line: line + 1, ch}, Math.min(50, cm.display.scroller.clientHeight / 4)); + cm.setCursor(line, ch); + found = true; + return true; + } + } + } + return { replaceStyle, save, From e32fecd1e37074aca5608f008ab00bc9b6f747f5 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 18:53:37 +0300 Subject: [PATCH 05/26] usercss: tint the active line's @mozdoc widget --- edit/codemirror-default.css | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/edit/codemirror-default.css b/edit/codemirror-default.css index 7cc0c8c3..5bf391a9 100644 --- a/edit/codemirror-default.css +++ b/edit/codemirror-default.css @@ -45,3 +45,18 @@ from { background-color: rgba(255, 255, 0, .4); } /* search color */ to { background-color: rgba(100, 255, 100, .4); } /* sarch + highlight */ } + +.CodeMirror-activeline .applies-to:before { + background-color: hsla(214, 100%, 90%, 0.15); + content: ""; + top: 1em; + left: 0; + right: 0; + bottom: 1em; + position: absolute; + pointer-events: none; +} + +.CodeMirror-activeline .applies-to ul { + z-index: 2; +} From 0ba3cfb725414f3a0823bf069dd9befe8c796788 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 19:38:03 +0300 Subject: [PATCH 06/26] FF: fix transition-bug-suppressor condition --- edit.html | 2 +- edit/codemirror-default.css | 2 +- manage.html | 2 +- options.html | 2 +- popup.html | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/edit.html b/edit.html index ee6b2fa3..2826b6bf 100644 --- a/edit.html +++ b/edit.html @@ -5,7 +5,7 @@