diff options
author | Alex Yatskov <alex@foosoft.net> | 2018-06-22 19:02:01 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2018-06-22 19:02:01 -0700 |
commit | 39cf302eefe1b3bc19e4a91c222872b322426354 (patch) | |
tree | 82481a22cc56ce36ecba30cf538584ddaa495033 /ext/fg/js | |
parent | 68cdd7d85b741d34133ea04b95a4eb1e49553ace (diff) | |
parent | 114f9a6ae91745bd1323071a1e485eb8b4c82967 (diff) |
Merge branch 'master' of https://github.com/FooSoft/yomichan
Diffstat (limited to 'ext/fg/js')
-rw-r--r-- | ext/fg/js/document.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 821a279f..9366832e 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -55,6 +55,8 @@ function docImposterCreate(element) { document.body.appendChild(imposter); imposter.scrollTop = element.scrollTop; imposter.scrollLeft = element.scrollLeft; + + return imposter; } function docImposterDestroy() { @@ -65,11 +67,12 @@ function docImposterDestroy() { function docRangeFromPoint(point) { const element = document.elementFromPoint(point.x, point.y); + let imposter = null; if (element) { if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') { return new TextSourceElement(element); } else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { - docImposterCreate(element); + imposter = docImposterCreate(element); } } @@ -86,6 +89,14 @@ function docRangeFromPoint(point) { } const range = document.caretRangeFromPoint(point.x, point.y); + + if(imposter !== null) imposter.style.zIndex = -2147483646; + + const rect = range.getClientRects()[0]; + if (point.y > rect.bottom + 2) { + return; + } + if (range) { return new TextSourceRange(range); } |