mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 01:52:31 +02:00
Make word under cursor detection more robust
This commit is contained in:
parent
f2f1c5d8d4
commit
80b1476aa2
2 changed files with 11 additions and 4 deletions
Binary file not shown.
|
|
@ -109,15 +109,22 @@ class CalibreUtils
|
|||
if range == null
|
||||
return null
|
||||
node = range.startContainer
|
||||
if node.nodeType != Node.TEXT_NODE
|
||||
if node?.nodeType != Node.TEXT_NODE
|
||||
return null
|
||||
offset = range.startOffset
|
||||
range = document.createRange()
|
||||
range.selectNodeContents(node)
|
||||
range.setStart(node, offset)
|
||||
range.setEnd(node, offset+1)
|
||||
try
|
||||
range.setStart(node, offset)
|
||||
range.setEnd(node, offset+1)
|
||||
catch error # Happens if offset is invalid
|
||||
null
|
||||
range.expand('word')
|
||||
return range.toString()
|
||||
ans = range.toString().trim()
|
||||
range.detach()
|
||||
matches = ans.split(/\b/)
|
||||
return if matches.length > 0 then matches[0] else null
|
||||
|
||||
# }}}
|
||||
|
||||
if window?
|
||||
|
|
|
|||
Loading…
Reference in a new issue