mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-29 08:53:07 +02:00
E-book viewer: When using a right click/shift-click to adjust the selection, move the section boundary that is closer to the click point. Fixes #1929164 [E-book viewer: Right- and Shift-clicking inside the selection always change its lower boundary](https://bugs.launchpad.net/calibre/+bug/1929164)
This commit is contained in:
parent
c62f144bd7
commit
de4bee60eb
2 changed files with 20 additions and 2 deletions
|
|
@ -67,7 +67,8 @@
|
|||
)
|
||||
from read_book.viewport import scroll_viewport
|
||||
from select import (
|
||||
first_visible_word, move_end_of_selection, selection_extents, word_at_point
|
||||
first_visible_word, is_start_closer_to_point, move_end_of_selection,
|
||||
selection_extents, word_at_point
|
||||
)
|
||||
from utils import debounce, is_ios
|
||||
|
||||
|
|
@ -809,7 +810,7 @@ def annotations_msg_received(self, data):
|
|||
except:
|
||||
(console.error or console.log)('Failed to extend selection to paragraph')
|
||||
elif dtype is 'extend-to-point':
|
||||
move_end_of_selection(data.pos, None)
|
||||
move_end_of_selection(data.pos, is_start_closer_to_point(data.pos))
|
||||
elif dtype is 'drag-scroll':
|
||||
self.scroll_to_extend_annotation(data.backwards)
|
||||
elif dtype is 'edit-highlight':
|
||||
|
|
|
|||
|
|
@ -190,6 +190,23 @@ def selection_extents(in_flow_mode):
|
|||
return range_extents(sel.getRangeAt(0), in_flow_mode)
|
||||
|
||||
|
||||
def is_start_closer_to_point(pos):
|
||||
sel = window.getSelection()
|
||||
if not sel.rangeCount:
|
||||
return
|
||||
p = caret_position_from_point(pos.x, pos.y)
|
||||
if p:
|
||||
r = sel.getRangeAt(0)
|
||||
sr = document.createRange()
|
||||
sr.setStart(r.startContainer, r.startOffset)
|
||||
sr.setEnd(p.offsetNode, p.offset)
|
||||
er = document.createRange()
|
||||
er.setStart(p.offsetNode, p.offset)
|
||||
er.setEnd(r.endContainer, r.endOffset)
|
||||
return sr.toString().length < er.toString().length
|
||||
return False
|
||||
|
||||
|
||||
def move_end_of_selection(pos, start):
|
||||
sel = window.getSelection()
|
||||
if not sel.rangeCount:
|
||||
|
|
|
|||
Loading…
Reference in a new issue