Viewing annots should be triggered by double click/long tap not single click/tap

This commit is contained in:
Kovid Goyal 2020-04-16 15:34:03 +05:30
parent 1b6c6f420b
commit b468f72ba7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 19 additions and 6 deletions

View File

@ -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(

View File

@ -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

View File

@ -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()