From 63a6098c2a00784d5c28e093114559d6331a1aa1 Mon Sep 17 00:00:00 2001 From: narcolepticinsomniac Date: Thu, 18 Oct 2018 23:05:47 -0400 Subject: [PATCH] Fixup usercss applies-to theme detection --- edit/applies-to-line-widget.js | 103 +++++++++++++++++---------------- edit/edit.css | 3 + 2 files changed, 57 insertions(+), 49 deletions(-) diff --git a/edit/applies-to-line-widget.js b/edit/applies-to-line-widget.js index fe995be7..0cdf7219 100644 --- a/edit/applies-to-line-widget.js +++ b/edit/applies-to-line-widget.js @@ -222,56 +222,61 @@ function createAppliesToLineWidget(cm) { requestAnimationFrame(updateWidgetStyle); return; } - const MIN_LUMA = .05; - const MIN_LUMA_DIFF = .4; - const color = { - wrapper: colorMimicry.get(cm.display.wrapper), - gutter: colorMimicry.get(cm.display.gutters, { - bg: 'backgroundColor', - border: 'borderRightColor', - }), - line: colorMimicry.get('.CodeMirror-linenumber', null, cm.display.lineDiv), - comment: colorMimicry.get('span.cm-comment', null, cm.display.lineDiv), - }; - const hasBorder = - color.gutter.style.borderRightWidth !== '0px' && - !/transparent|\b0\)/g.test(color.gutter.style.borderRightColor); - const diff = { - wrapper: Math.abs(color.gutter.bgLuma - color.wrapper.foreLuma), - border: hasBorder ? Math.abs(color.gutter.bgLuma - color.gutter.borderLuma) : 0, - line: Math.abs(color.gutter.bgLuma - color.line.foreLuma), - }; - const preferLine = diff.line > diff.wrapper || diff.line > MIN_LUMA_DIFF; - const fore = preferLine ? color.line.fore : color.wrapper.fore; + if (prefs.get('editor.theme') !== 'default') { + const MIN_LUMA = .05; + const MIN_LUMA_DIFF = .4; + const color = { + wrapper: colorMimicry.get(cm.display.wrapper), + gutter: colorMimicry.get(cm.display.gutters, { + bg: 'backgroundColor', + border: 'borderRightColor', + }), + line: colorMimicry.get('.CodeMirror-linenumber', null, cm.display.lineDiv), + comment: colorMimicry.get('span.cm-comment', null, cm.display.lineDiv), + }; + const hasBorder = + color.gutter.style.borderRightWidth !== '0px' && + !/transparent|\b0\)/g.test(color.gutter.style.borderRightColor); + const diff = { + wrapper: Math.abs(color.gutter.bgLuma - color.wrapper.foreLuma), + border: hasBorder ? Math.abs(color.gutter.bgLuma - color.gutter.borderLuma) : 0, + line: Math.abs(color.gutter.bgLuma - color.line.foreLuma), + }; + const preferLine = diff.line > diff.wrapper || diff.line > MIN_LUMA_DIFF; + const fore = preferLine ? color.line.fore : color.wrapper.fore; - const border = fore.replace(/[\d.]+(?=\))/, MIN_LUMA_DIFF / 2); - const borderStyleForced = `1px ${hasBorder ? color.gutter.style.borderRightStyle : 'solid'} ${border}`; + const border = fore.replace(/[\d.]+(?=\))/, MIN_LUMA_DIFF / 2); + const borderStyleForced = `1px ${hasBorder ? color.gutter.style.borderRightStyle : 'solid'} ${border}`; - actualStyle.textContent = ` - .applies-to { - background-color: ${color.gutter.bg}; - border-top: ${borderStyleForced}; - border-bottom: ${borderStyleForced}; - } - .applies-to label { - color: ${fore}; - } - .applies-to input, - .applies-to button, - .applies-to select { - background: rgba(255, 255, 255, ${ - Math.max(MIN_LUMA, Math.pow(Math.max(0, color.gutter.bgLuma - MIN_LUMA * 2), 2)).toFixed(2) - }); - border: ${borderStyleForced}; - transition: none; - color: ${fore}; - } - .applies-to .svg-icon.select-arrow { - fill: ${fore}; - transition: none; - } - `; - document.documentElement.appendChild(actualStyle); + actualStyle.textContent = ` + .applies-to { + background-color: ${color.gutter.bg}; + border-top: ${borderStyleForced}; + border-bottom: ${borderStyleForced}; + } + .applies-to label { + color: ${fore}; + } + .applies-to input, + .applies-to select { + background-color: rgba(255, 255, 255, ${ + Math.max(MIN_LUMA, Math.pow(Math.max(0, color.gutter.bgLuma - MIN_LUMA * 2), 2)).toFixed(2) + }); + border: ${borderStyleForced}; + transition: none; + color: ${fore}; + } + .applies-to .svg-icon.select-arrow { + fill: ${fore} !important; + } + .applies-to select option { + background-color: ${color.gutter.bg}; + } + `; + document.documentElement.appendChild(actualStyle); + } else if (prefs.get('editor.theme') === 'default') { + actualStyle.textContent = ''; + } } function doUpdate() { @@ -283,7 +288,7 @@ function createAppliesToLineWidget(cm) { if (i === -2) { i = widgets.length - 1; } - if (j < 0) { + if (j < 0) {actualStyle j = widgets.length; } diff --git a/edit/edit.css b/edit/edit.css index 32c10b5e..aab5407a 100644 --- a/edit/edit.css +++ b/edit/edit.css @@ -806,6 +806,9 @@ html:not(.usercss) .usercss-only, margin: 1em 0; padding: .75rem .75rem .25rem; padding-right: calc(1em + 20px); +} + +.CodeMirror.cm-s-default .CodeMirror-linewidget .applies-to { background-color: var(--gray-lightness-90); border-top: 1px solid var(--truegray-alpha-3); border-bottom: 1px solid var(--truegray-alpha-3);