mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix typo in ported cfi module
Was causing at_point() to return CFIs based on spatial offsets instead of containing element + text offset
This commit is contained in:
parent
52b3964ce6
commit
f8bfedfa8d
@ -508,28 +508,28 @@ def at_point(ox, oy): # {{{
|
|||||||
Math.sqrt(Math.pow(p1[0]-p2[0], 2), Math.pow(p1[1]-p2[1], 2))
|
Math.sqrt(Math.pow(p1[0]-p2[0], 2), Math.pow(p1[1]-p2[1], 2))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cfi = window.cfi.at(ox, oy)
|
cfi = at(ox, oy)
|
||||||
point = window.cfi.point(cfi)
|
p = point(cfi)
|
||||||
except Exception:
|
except Exception:
|
||||||
cfi = None
|
cfi = None
|
||||||
|
|
||||||
|
|
||||||
if cfi:
|
if cfi:
|
||||||
if point.range is not None:
|
if p.range is not None:
|
||||||
r = point.range
|
r = p.range
|
||||||
rect = r.getClientRects()[0]
|
rect = r.getClientRects()[0]
|
||||||
|
|
||||||
x = (point.a*rect.left + (1-point.a)*rect.right)
|
x = (p.a*rect.left + (1-p.a)*rect.right)
|
||||||
y = (rect.top + rect.bottom)/2
|
y = (rect.top + rect.bottom)/2
|
||||||
x, y = viewport_to_document(x, y, r.startContainer.ownerDocument)
|
x, y = viewport_to_document(x, y, r.startContainer.ownerDocument)
|
||||||
else:
|
else:
|
||||||
node = point.node
|
node = p.node
|
||||||
r = node.getBoundingClientRect()
|
r = node.getBoundingClientRect()
|
||||||
x, y = viewport_to_document(r.left, r.top, node.ownerDocument)
|
x, y = viewport_to_document(r.left, r.top, node.ownerDocument)
|
||||||
if type(point.x) is 'number' and node.offsetWidth:
|
if type(p.x) is 'number' and node.offsetWidth:
|
||||||
x += (point.x*node.offsetWidth)/100
|
x += (p.x*node.offsetWidth)/100
|
||||||
if type(point.y) is 'number' and node.offsetHeight:
|
if type(p.y) is 'number' and node.offsetHeight:
|
||||||
y += (point.y*node.offsetHeight)/100
|
y += (p.y*node.offsetHeight)/100
|
||||||
|
|
||||||
if dist(viewport_to_document(ox, oy), v'[x, y]') > 50:
|
if dist(viewport_to_document(ox, oy), v'[x, y]') > 50:
|
||||||
cfi = None
|
cfi = None
|
||||||
@ -540,7 +540,6 @@ def at_point(ox, oy): # {{{
|
|||||||
def at_current(): # {{{
|
def at_current(): # {{{
|
||||||
winx, winy = window_scroll_pos()
|
winx, winy = window_scroll_pos()
|
||||||
winw, winh = window.innerWidth, window.innerHeight
|
winw, winh = window.innerWidth, window.innerHeight
|
||||||
max = Math.max
|
|
||||||
winw = max(winw, 400)
|
winw = max(winw, 400)
|
||||||
winh = max(winh, 600)
|
winh = max(winh, 600)
|
||||||
deltay = Math.floor(winh/50)
|
deltay = Math.floor(winh/50)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user