mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix adding of more than one custom highlight style broken
This commit is contained in:
parent
d862d271f2
commit
e0926d1dfe
@ -70,7 +70,7 @@ def all_builtin_styles():
|
|||||||
ans.push({'type': 'builtin', 'kind': 'decoration', 'which': which})
|
ans.push({'type': 'builtin', 'kind': 'decoration', 'which': which})
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
all_style_keys = v"'type kind which background-color text-decoration-line text-decoration-color text-decoration-style'.split(' ')"
|
all_style_keys = v"'type kind which light dark background-color text-decoration-line text-decoration-color text-decoration-style'.split(' ')"
|
||||||
|
|
||||||
|
|
||||||
def custom_color_theme(name, lightbg, darkbg):
|
def custom_color_theme(name, lightbg, darkbg):
|
||||||
@ -298,6 +298,10 @@ class AddStyle: # {{{
|
|||||||
def focus(self):
|
def focus(self):
|
||||||
self.get_container().querySelector('input[name=friendly_name]').focus()
|
self.get_container().querySelector('input[name=friendly_name]').focus()
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.get_container().querySelector('input[name=friendly_name]').value = ''
|
||||||
|
self.focus()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def style_type(self):
|
def style_type(self):
|
||||||
return self.get_container().querySelector('input[name=style_type]:checked').value
|
return self.get_container().querySelector('input[name=style_type]:checked').value
|
||||||
@ -411,7 +415,7 @@ class EditNotesAndColors: # {{{
|
|||||||
c = self.container
|
c = self.container
|
||||||
c.firstChild.style.display = 'none'
|
c.firstChild.style.display = 'none'
|
||||||
c.lastChild.style.display = 'block'
|
c.lastChild.style.display = 'block'
|
||||||
self.add_style.focus()
|
self.add_style.init()
|
||||||
))
|
))
|
||||||
|
|
||||||
self.set_visibility_of_remove_button()
|
self.set_visibility_of_remove_button()
|
||||||
@ -426,13 +430,26 @@ class EditNotesAndColors: # {{{
|
|||||||
self.notes_edit.focus()
|
self.notes_edit.focus()
|
||||||
|
|
||||||
def add_new_style(self, new_style):
|
def add_new_style(self, new_style):
|
||||||
item = self.add_color(HighlightStyle(new_style), True)
|
hs = HighlightStyle(new_style)
|
||||||
item.classList.add('custom-style')
|
item = self.add_color(hs, True)
|
||||||
self.make_swatch_current(item)
|
if not item:
|
||||||
sd = get_session_data()
|
# happens if the newly created style is the same as some existing
|
||||||
custom_highlight_styles = sd.get('custom_highlight_styles')
|
# style
|
||||||
custom_highlight_styles.unshift(new_style)
|
for q in self.container.getElementsByClassName('swatch'):
|
||||||
sd.set('custom_highlight_styles', custom_highlight_styles)
|
if q.dataset.key is hs.key:
|
||||||
|
item = q
|
||||||
|
break
|
||||||
|
if item:
|
||||||
|
item.classList.add('custom-style')
|
||||||
|
self.make_swatch_current(item)
|
||||||
|
sd = get_session_data()
|
||||||
|
new_styles = v'[new_style]'
|
||||||
|
seen = {hs.key: True}
|
||||||
|
for style in sd.get('custom_highlight_styles'):
|
||||||
|
hso = HighlightStyle(style)
|
||||||
|
if not seen[hso.key]:
|
||||||
|
new_styles.push(style)
|
||||||
|
sd.set('custom_highlight_styles', new_styles)
|
||||||
|
|
||||||
def set_visibility_of_remove_button(self):
|
def set_visibility_of_remove_button(self):
|
||||||
c = self.container
|
c = self.container
|
||||||
@ -454,7 +471,9 @@ class EditNotesAndColors: # {{{
|
|||||||
)
|
)
|
||||||
if is_current:
|
if is_current:
|
||||||
item.classList.add('current-swatch')
|
item.classList.add('current-swatch')
|
||||||
|
item.classList.add('swatch')
|
||||||
item.dataset.style = hs.serialized()
|
item.dataset.style = hs.serialized()
|
||||||
|
item.dataset.key = hs.key
|
||||||
parent = self.container.getElementsByClassName('color-block')[0]
|
parent = self.container.getElementsByClassName('color-block')[0]
|
||||||
if at_start:
|
if at_start:
|
||||||
parent.insertBefore(item, parent.firstChild)
|
parent.insertBefore(item, parent.firstChild)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user