E-book viewer: Allow using shift+click to extend selections. Fixes #1918251 [E-book viewer selection broken](https://bugs.launchpad.net/calibre/+bug/1918251)

This commit is contained in:
Kovid Goyal 2021-03-10 13:19:35 +05:30
parent 8d244b4a45
commit cbd1c42865
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 19 additions and 0 deletions

View File

@ -111,6 +111,8 @@ highlight. You can add notes and change the color of the highlight. On a touch
screen, long tap a word to select it and show the popup bar. Once in highlight screen, long tap a word to select it and show the popup bar. Once in highlight
mode you can change what text is selected, using touch screen friendly selection mode you can change what text is selected, using touch screen friendly selection
handles. Drag the handles to the top or bottom margins to scroll while selecting. handles. Drag the handles to the top or bottom margins to scroll while selecting.
You can also hold the :kbd:`Shift` key and click to extend the selection,
particularly useful for multi-page selections.
You can use the :guilabel:`Highlights` button in the viewer You can use the :guilabel:`Highlights` button in the viewer
controls to show a separate panel with a list of all highlights in the book, controls to show a separate panel with a list of all highlights in the book,

View File

@ -810,6 +810,8 @@ class IframeBoss:
sel.setBaseAndExtent(sel.focusNode, sel.focusOffset, end_node, end_offset) sel.setBaseAndExtent(sel.focusNode, sel.focusOffset, end_node, end_offset)
except: except:
(console.error or console.log)('Failed to extend selection to paragraph') (console.error or console.log)('Failed to extend selection to paragraph')
elif dtype is 'extend-to-point':
move_end_of_selection(data.pos, None)
elif dtype is 'drag-scroll': elif dtype is 'drag-scroll':
self.scroll_to_extend_annotation(data.backwards) self.scroll_to_extend_annotation(data.backwards)
elif dtype is 'edit-highlight': elif dtype is 'edit-highlight':

View File

@ -480,6 +480,11 @@ class SelectionBar:
self.hide_editor(True) self.hide_editor(True)
if self.state is WAITING: if self.state is WAITING:
now = window.performance.now() now = window.performance.now()
if ev.shiftKey:
pos = {'x': ev.clientX, 'y': ev.clientY}
map_to_iframe_coords(pos, get_margins())
self.send_message('extend-to-point', pos=pos)
return
if self.last_double_click_at and now - self.last_double_click_at < 500: if self.last_double_click_at and now - self.last_double_click_at < 500:
self.send_message('extend-to-paragraph') self.send_message('extend-to-paragraph')
return return

View File

@ -197,6 +197,16 @@ def move_end_of_selection(pos, start):
p = caret_position_from_point(pos.x, pos.y) p = caret_position_from_point(pos.x, pos.y)
if p: if p:
r = sel.getRangeAt(0) r = sel.getRangeAt(0)
if start is None:
q = document.createRange()
q.setStart(p.offsetNode, p.offset)
q.setEnd(p.offsetNode, p.offset)
if r.compareBoundaryPoints(window.Range.START_TO_START, q) >= 0:
start = True
elif r.compareBoundaryPoints(window.Range.END_TO_END, q) <= 0:
start = False
else:
return
if start: if start:
if r.startContainer is not p.offsetNode or r.startOffset is not p.offset: if r.startContainer is not p.offsetNode or r.startOffset is not p.offset:
r.setStart(p.offsetNode, p.offset) r.setStart(p.offsetNode, p.offset)