mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix incorrect mapping of CFI to position for CFI at the start of a tag whose contents are wrapped in an annotation span
This commit is contained in:
parent
873d6080fd
commit
abba1ef004
@ -566,9 +566,13 @@ def point(cfi, doc): # {{{
|
|||||||
else:
|
else:
|
||||||
try_list = [{'start':0, 'end':0, 'a':0.5}, {'start':-1, 'end':0, 'a':0}, {'start':0, 'end':1, 'a':1}]
|
try_list = [{'start':0, 'end':0, 'a':0.5}, {'start':-1, 'end':0, 'a':0}, {'start':0, 'end':1, 'a':1}]
|
||||||
a = None
|
a = None
|
||||||
rects = None
|
|
||||||
node_len = node.nodeValue.length if node.nodeValue else 0
|
node_len = node.nodeValue.length if node.nodeValue else 0
|
||||||
offset = r.offset
|
offset = r.offset
|
||||||
|
if not offset:
|
||||||
|
range_.setStart(node, 0)
|
||||||
|
range_.setEnd(node, 0)
|
||||||
|
else:
|
||||||
|
rects = v'[]'
|
||||||
for v'var i = 0; i < 2; i++':
|
for v'var i = 0; i < 2; i++':
|
||||||
# Try reducing the offset by 1 if we get no match as if it refers to the position after the
|
# Try reducing the offset by 1 if we get no match as if it refers to the position after the
|
||||||
# last character we wont get a match with getClientRects
|
# last character we wont get a match with getClientRects
|
||||||
@ -576,7 +580,7 @@ def point(cfi, doc): # {{{
|
|||||||
if offset < 0:
|
if offset < 0:
|
||||||
offset = 0
|
offset = 0
|
||||||
k = 0
|
k = 0
|
||||||
while (not rects or not rects.length) and k < try_list.length:
|
while not rects?.length and k < try_list.length:
|
||||||
t = try_list[k]
|
t = try_list[k]
|
||||||
k += 1
|
k += 1
|
||||||
start_offset = offset + t.start
|
start_offset = offset + t.start
|
||||||
@ -588,8 +592,8 @@ def point(cfi, doc): # {{{
|
|||||||
range_.setEnd(node, end_offset)
|
range_.setEnd(node, end_offset)
|
||||||
rects = range_.getClientRects()
|
rects = range_.getClientRects()
|
||||||
|
|
||||||
if not rects or not rects.length:
|
if not rects?.length:
|
||||||
print(str.format("Could not find caret position: rects: {} offset: {}", rects, r.offset))
|
print(str.format("Could not find caret position for {} : rects: {} offset: {}", cfi, rects, r.offset))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user