mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
68d0bf7080
commit
4027c32a26
@ -122,18 +122,14 @@ offset_in_text_node = (node, range, x, y) ->
|
|||||||
find_offset_for_point = (x, y, node, cdoc) ->
|
find_offset_for_point = (x, y, node, cdoc) ->
|
||||||
range = cdoc.createRange()
|
range = cdoc.createRange()
|
||||||
child = node.firstChild
|
child = node.firstChild
|
||||||
last_child = null
|
|
||||||
while child
|
while child
|
||||||
if child.nodeType in [3, 4, 5, 6] and child.nodeValue?.length
|
if child.nodeType in [3, 4, 5, 6] and child.nodeValue?.length
|
||||||
range.setStart(child, 0)
|
range.setStart(child, 0)
|
||||||
range.setEnd(child, child.nodeValue.length)
|
range.setEnd(child, child.nodeValue.length)
|
||||||
if range_has_point(range, x, y)
|
if range_has_point(range, x, y)
|
||||||
return [child, offset_in_text_node(child, range, x, y)]
|
return [child, offset_in_text_node(child, range, x, y)]
|
||||||
last_child = child
|
|
||||||
child = child.nextSibling
|
child = child.nextSibling
|
||||||
|
|
||||||
if not last_child
|
|
||||||
throw "#{node} has no children"
|
|
||||||
# The point must be after the last bit of text/in the padding/border, we dont know
|
# The point must be after the last bit of text/in the padding/border, we dont know
|
||||||
# how to get a good point in this case
|
# how to get a good point in this case
|
||||||
throw "Point (#{x}, #{y}) is in the padding/border of #{node}, so cannot calculate offset"
|
throw "Point (#{x}, #{y}) is in the padding/border of #{node}, so cannot calculate offset"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user