More hints work

This commit is contained in:
Kovid Goyal 2020-12-15 16:14:52 +05:30
parent 5f113ce9dc
commit 168c75d5d1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 1 deletions

View File

@ -12,6 +12,11 @@ class Hints:
container.style.overflow = 'hidden' container.style.overflow = 'hidden'
container.addEventListener('keydown', self.on_keydown, {'passive': False}) container.addEventListener('keydown', self.on_keydown, {'passive': False})
container.addEventListener('click', self.container_clicked, {'passive': False}) container.addEventListener('click', self.container_clicked, {'passive': False})
self.reset()
def reset(self):
self.hints_map = {}
self.current_prefix = ''
@property @property
def container(self): def container(self):
@ -28,9 +33,11 @@ class Hints:
if self.is_visible: if self.is_visible:
self.container.style.display = 'none' self.container.style.display = 'none'
self.send_message('hide') self.send_message('hide')
self.reset()
def show(self): def show(self):
if not self.is_visible: if not self.is_visible:
self.reset()
self.container.style.display = 'block' self.container.style.display = 'block'
self.focus() self.focus()
self.send_message('show') self.send_message('show')
@ -47,6 +54,7 @@ class Hints:
def handle_message(self, msg): def handle_message(self, msg):
if msg.type is 'shown': if msg.type is 'shown':
self.reset()
self.hints_map = msg.hints_map self.hints_map = msg.hints_map
@ -66,7 +74,7 @@ def hint_visible_links(link_attr):
h = i + '' h = i + ''
a.setAttribute('calibre-hint-render', i.toString(36)) a.setAttribute('calibre-hint-render', i.toString(36))
a.setAttribute('calibre-hint-value', h) a.setAttribute('calibre-hint-value', h)
hint_map[h] = a.getAttribute(link_attr) hint_map[h] = {'type': 'link', 'data':a.getAttribute(link_attr)}
a.classList.add('calibre-hint-visible') a.classList.add('calibre-hint-visible')
return hint_map return hint_map

View File

@ -297,6 +297,7 @@ class View:
, ,
'annotations': self.on_annotations_message, 'annotations': self.on_annotations_message,
'tts': self.on_tts_message, 'tts': self.on_tts_message,
'hints': self.on_hints_message,
'copy_text_to_clipboard': def(data): 'copy_text_to_clipboard': def(data):
ui_operations.copy_selection(data.text, data.html) ui_operations.copy_selection(data.text, data.html)
, ,