Edit book: Preview panel: In dark mode when all of the background/foreground/link colors are set to "No change" do not render the book using dark colors

This commit is contained in:
Kovid Goyal 2022-10-07 23:28:19 +05:30
parent 66c7741822
commit 37fd854e33
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 2 deletions

View File

@ -407,7 +407,9 @@ class PreviewSettings(BasicSettings): # {{{
ans.setObjectName(name)
return ans
b('unset', _('No change'), _('Use the colors from the book styles, defaulting to black-on-white'))
b('unset', _('No change'), _('Use the colors from the book styles, defaulting to black-on-white.'
' Note that in dark mode, you must set all three colors to "No change"'
' otherwise the book is rendered with dark colors.'))
b('auto', _('Theme based'), _('When using a dark theme force dark colors, otherwise same as "No change"'))
b('manual', _('Custom'), _('Choose a custom color'))

View File

@ -277,7 +277,9 @@ def create_dark_mode_script():
function apply_css() {
var css = '';
if (settings.link) css += 'html > body :link, html > body :link * { color: ' + settings.link + ' !important; }';
if (settings.is_dark_theme) { css = ':root { color-scheme: dark; }' + css; }
var using_custom_colors = false;
if (settings.bg || settings.fg || settings.link) using_custom_colors = true;
if (settings.is_dark_theme && using_custom_colors) { css = ':root { color-scheme: dark; }' + css; }
var style = document.createElement('style');
style.textContent = css;
document.documentElement.appendChild(style);