Make selection background opaque on chrome

This commit is contained in:
Kovid Goyal 2020-07-20 17:01:50 +05:30
parent 29215758c3
commit e0f1953ae6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -46,6 +46,13 @@ def default_selection_colors():
return '#3297FD', '#ddd'
def make_selection_background_opaque(selbg):
# see https://stackoverflow.com/questions/7224445/css3-selection-behaves-differently-in-ff-chrome
if selbg and selbg.startsWith('#') and len(selbg) is 7:
selbg += 'fe'
return selbg
styles_id = 'calibre-color-scheme-style-overrides'
@ -78,6 +85,7 @@ def apply_colors():
text += f'\nhtml > body :link, html > body :link * {{ color: {c} !important }} html > body :visited, html > body :visited * {{ color: {c} !important }}'
selbg, selfg = default_selection_colors()
selbg = make_selection_background_opaque(selbg)
text += f'\n::selection {{ background-color: {selbg}; color: {selfg} }}'
text += f'\n::selection:window-inactive {{ background-color: {selbg}; color: {selfg} }}'
@ -92,6 +100,8 @@ def set_selection_style(style):
if not sheet:
return
css_text = ''
if style.selbg:
style.selbg = make_selection_background_opaque(style.selbg)
for prop in Object.keys(style):
css_text += f'{prop}: {style[prop]}; '
for rule in sheet.sheet.cssRules: