Restore triple-click to select paragraphs

This commit is contained in:
Kovid Goyal 2020-08-08 22:04:27 +05:30
parent 3af812813c
commit 72fcbbc93a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 0 deletions

View File

@ -180,6 +180,7 @@ class IframeBoss:
window.addEventListener('keydown', self.onkeydown, {'passive': False}) window.addEventListener('keydown', self.onkeydown, {'passive': False})
window.addEventListener('mousemove', self.onmousemove, {'passive': True}) window.addEventListener('mousemove', self.onmousemove, {'passive': True})
window.addEventListener('mouseup', self.onmouseup, {'passive': True}) window.addEventListener('mouseup', self.onmouseup, {'passive': True})
window.addEventListener('dblclick', self.ondoubleclick, {'passive': True})
document.documentElement.addEventListener('contextmenu', self.oncontextmenu, {'passive': False}) document.documentElement.addEventListener('contextmenu', self.oncontextmenu, {'passive': False})
document.addEventListener('selectionchange', self.onselectionchange) document.addEventListener('selectionchange', self.onselectionchange)
self.color_scheme = data.color_scheme self.color_scheme = data.color_scheme
@ -592,6 +593,9 @@ class IframeBoss:
# ensure selection bar is updated # ensure selection bar is updated
self.onselectionchange() self.onselectionchange()
def ondoubleclick(self, evt):
self.send_message('annotations', type='double-click')
def onkeydown(self, evt): def onkeydown(self, evt):
if current_layout_mode() is not 'flow' and evt.key is 'Tab': if current_layout_mode() is not 'flow' and evt.key is 'Tab':
# Prevent the TAB key from shifting focus as it causes partial scrolling # Prevent the TAB key from shifting focus as it causes partial scrolling
@ -724,6 +728,12 @@ class IframeBoss:
set_selection_style(data.style) set_selection_style(data.style)
elif data.type is 'trigger-shortcut': elif data.type is 'trigger-shortcut':
self.on_handle_navigation_shortcut(data) self.on_handle_navigation_shortcut(data)
elif data.type is 'extend-to-paragraph':
sel = window.getSelection()
sel.modify('extend', 'forward', 'paragraphboundary')
end_node, end_offset = sel.focusNode, sel.focusOffset
sel.modify('extend', 'backward', 'paragraphboundary')
sel.setBaseAndExtent(sel.focusNode, sel.focusOffset, end_node, end_offset)
elif data.type is 'edit-highlight': elif data.type is 'edit-highlight':
crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid] crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid]
if crw_ and select_crw(crw_): if crw_ and select_crw(crw_):

View File

@ -405,6 +405,10 @@ class SelectionBar:
if self.state is EDITING: if self.state is EDITING:
self.hide_editor(True) self.hide_editor(True)
if self.state is WAITING: if self.state is WAITING:
now = window.performance.now()
if self.last_double_click_at and now - self.last_double_click_at < 500:
self.send_message('extend-to-paragraph')
return
for x in (self.bar, self.left_handle, self.right_handle): for x in (self.bar, self.left_handle, self.right_handle):
if near_element(x, ev.clientX, ev.clientY): if near_element(x, ev.clientX, ev.clientY):
return return
@ -783,6 +787,8 @@ class SelectionBar:
elif msg.type is 'edit-highlight': elif msg.type is 'edit-highlight':
if self.state is WAITING: if self.state is WAITING:
self.create_highlight() self.create_highlight()
elif msg.type is 'double-click':
self.last_double_click_at = window.performance.now()
else: else:
print('Ignoring annotations message with unknown type:', msg.type) print('Ignoring annotations message with unknown type:', msg.type)