From 8828bc0e619da8f39832011ea506406ce955aac0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Sep 2023 08:58:10 +0530 Subject: [PATCH] E-book viewer: Fix modifying, then jumping to and then modifying the highlight again from the highlights panel causing the highlight to be deleted. Fixes #2033981 [E-book viewer: highlights get unexpectedly deleted](https://bugs.launchpad.net/calibre/+bug/2033981) --- src/pyj/range_utils.pyj | 3 +-- src/pyj/read_book/iframe.pyj | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pyj/range_utils.pyj b/src/pyj/range_utils.pyj index b408f796d9..a69a1116ec 100644 --- a/src/pyj/range_utils.pyj +++ b/src/pyj/range_utils.pyj @@ -143,8 +143,7 @@ def select_crw(crw): sel.removeAllRanges() sel.addRange(r) return True - else: - print(f'range-wrapper: {crw} does not exist') + print(f'range-wrapper: {crw} does not exist') return False diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index c525133993..793ff5e1d9 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -877,8 +877,12 @@ class IframeBoss: elif dtype is 'drag-scroll': self.scroll_to_extend_annotation(data.backwards) elif dtype is 'edit-highlight': - crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid] - if crw_ and select_crw(crw_): + found_highlight_to_edit = False + for qcrw, quuid in Object.entries(annot_id_uuid_map): + if quuid is data.uuid and select_crw(qcrw): + found_highlight_to_edit = True + break + if found_highlight_to_edit: self.ensure_selection_visible() window.setTimeout(def(): self.send_message('annotations', type='edit-highlight')