mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Better calculation of selection extents
This commit is contained in:
parent
0407959ce4
commit
8aad5bd72f
@ -63,13 +63,19 @@ def range_extents(start, end, in_flow_mode):
|
|||||||
def for_boundary(r, ans):
|
def for_boundary(r, ans):
|
||||||
rect = r.getBoundingClientRect()
|
rect = r.getBoundingClientRect()
|
||||||
if rect.height is 0:
|
if rect.height is 0:
|
||||||
|
# this tends to happen when moving the mouse downwards
|
||||||
|
# at the boundary between paragraphs
|
||||||
if r.startContainer?.nodeType is Node.ELEMENT_NODE:
|
if r.startContainer?.nodeType is Node.ELEMENT_NODE:
|
||||||
node = r.startContainer
|
node = r.startContainer
|
||||||
if r.startOffset and node.childNodes.length > r.startOffset:
|
if r.startOffset and node.childNodes.length > r.startOffset:
|
||||||
node = node.childNodes[r.startOffset]
|
node = node.childNodes[r.startOffset]
|
||||||
if node.getBoundingClientRect:
|
# we cant use getBoundingClientRect as the node might be split
|
||||||
erect = node.getBoundingClientRect()
|
# among multiple columns
|
||||||
rect = {'left': erect.left, 'top': erect.top, 'right': erect.right, 'bottom': erect.bottom, 'width': erect.width, 'height': 2}
|
if node.getClientRects:
|
||||||
|
rects = node.getClientRects()
|
||||||
|
if rects.length:
|
||||||
|
erect = rects[0]
|
||||||
|
rect = {'left': erect.left, 'top': erect.top, 'right': erect.left + 2, 'bottom': erect.top + 2, 'width': 2, 'height': 2}
|
||||||
ans.x = Math.round(rect.left)
|
ans.x = Math.round(rect.left)
|
||||||
ans.y = Math.round(rect.top)
|
ans.y = Math.round(rect.top)
|
||||||
ans.height = rect.height
|
ans.height = rect.height
|
||||||
|
Loading…
x
Reference in New Issue
Block a user