From b468f72ba770906aed00519ad683461ee4c2755b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Apr 2020 15:34:03 +0530 Subject: [PATCH] Viewing annots should be triggered by double click/long tap not single click/tap --- src/pyj/read_book/create_annotation.pyj | 2 +- src/pyj/read_book/extract.pyj | 8 +++++++- src/pyj/read_book/iframe.pyj | 15 +++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/pyj/read_book/create_annotation.pyj b/src/pyj/read_book/create_annotation.pyj index ee31ee77f8..9e2a53b18b 100644 --- a/src/pyj/read_book/create_annotation.pyj +++ b/src/pyj/read_book/create_annotation.pyj @@ -275,7 +275,7 @@ class CreateAnnotation: ta.focus() ), E.div( - _('To view the notes for a highlight, tap or click on it.'), + _('To view the notes for a highlight, long-tap or double click on it.'), style='font-size-smaller; margin-left: 1rem; margin-right: 1rem' ), E.a( diff --git a/src/pyj/read_book/extract.pyj b/src/pyj/read_book/extract.pyj index 20a632dccb..031638595b 100644 --- a/src/pyj/read_book/extract.pyj +++ b/src/pyj/read_book/extract.pyj @@ -3,13 +3,19 @@ from __python__ import bound_methods, hash_literals +from read_book.globals import get_boss + def get_elements(x, y): nonlocal img_id_counter - ans = {'link': None, 'img': None} + ans = {'link': None, 'img': None, 'highlight': None} for elem in document.elementsFromPoint(x, y): if elem.tagName.toLowerCase() is 'a' and elem.getAttribute('href') and not ans.link: ans.link = elem.getAttribute('href') elif elem.tagName.toLowerCase() is 'img' and elem.getAttribute('data-calibre-src') and not ans.img: ans.img = elem.getAttribute('data-calibre-src') + elif elem.dataset?.calibreRangeWrapper: + annot_id = get_boss().annot_id_uuid_map[elem.dataset.calibreRangeWrapper] + if annot_id: + ans.highlight = annot_id return ans diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 227c0db712..ba4f5ccf33 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -271,6 +271,9 @@ class IframeBoss: if elements.img: self.send_message('view_image', calibre_src=elements.img) return + if elements.highlight: + self.activate_annotation(elements.highlight) + return r = word_at_point(gesture.viewport_x, gesture.viewport_y) if r: s = document.getSelection() @@ -747,13 +750,17 @@ class IframeBoss: v'delete self.annot_id_uuid_map[crw]' def add_highlight_listeners(self, wrapper): - wrapper.addEventListener('click', self.highlight_wrapper_clicked) + wrapper.addEventListener('dblclick', self.highlight_wrapper_dblclicked) - def highlight_wrapper_clicked(self, ev): - crw = ev.currentTarget.dataset.calibreRangeWrapper - uuid = self.annot_id_uuid_map[crw] + def activate_annotation(self, uuid): if uuid: self.send_message('annotations', type='annotation-activated', uuid=uuid) + window.getSelection().removeAllRanges() + + def highlight_wrapper_dblclicked(self, ev): + crw = ev.currentTarget.dataset.calibreRangeWrapper + ev.preventDefault(), ev.stopPropagation() + self.activate_annotation(self.annot_id_uuid_map[crw]) def copy_selection(self): text = window.getSelection().toString()