Fix notes indicator not being updated when editing notes from the highlights panels

This commit is contained in:
Kovid Goyal 2020-08-17 21:29:45 +05:30
parent 832211b904
commit 7db1a9d0a4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 23 additions and 2 deletions

View File

@ -152,6 +152,12 @@ def wrap_text_in_range(styler, r, class_to_add_to_last, process_wrapper):
return crw, Object.keys(intersecting_wrappers)
def last_span_for_crw(crw):
nodes = document.querySelectorAll(f'span[data-calibre-range-wrapper="{crw}"]')
if nodes and nodes.length:
return nodes[-1]
def reset_highlight_counter():
nonlocal wrapper_counter
wrapper_counter = 0

View File

@ -9,8 +9,8 @@ from select import move_end_of_selection, selection_extents, word_at_point
from fs_images import fix_fullscreen_svg_images
from iframe_comm import IframeClient
from range_utils import (
highlight_associated_with_selection, reset_highlight_counter, select_crw,
unwrap_all_crw, unwrap_crw, wrap_text_in_range
highlight_associated_with_selection, last_span_for_crw, reset_highlight_counter,
select_crw, unwrap_all_crw, unwrap_crw, wrap_text_in_range
)
from read_book.cfi import cfi_for_selection, range_from_cfi
from read_book.extract import get_elements
@ -752,6 +752,16 @@ class IframeBoss:
window.setTimeout(def():
self.send_message('annotations', type='edit-highlight')
, 50)
elif data.type is 'notes-edited':
cls = 'crw-has-dot'
crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid]
if crw_:
node = last_span_for_crw(crw_)
if node:
if data.has_notes:
node.classList.add(cls)
else:
node.classList.remove(cls)
elif data.type is 'remove-highlight':
crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid]
if crw_:

View File

@ -828,6 +828,10 @@ class SelectionBar:
def send_message(self, type, **kw):
self.view.iframe_wrapper.send_message('annotations', type=type, **kw)
def notes_edited(self, annot_id):
notes = self.annotations_manager.notes_for_highlight(annot_id)
self.send_message('notes-edited', uuid=annot_id, has_notes=bool(notes))
def handle_message(self, msg):
if msg.type is 'highlight-applied':
notes = self.current_notes

View File

@ -1066,6 +1066,7 @@ class View:
def set_notes_for_highlight(self, uuid, notes):
if self.annotations_manager.set_notes_for_highlight(uuid, notes):
self.selection_bar.notes_edited(uuid)
self.selection_bar.update_position()
def on_next_spine_item(self, data):