diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-08-09 21:45:29 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-08-09 21:45:29 -0400 |
commit | 710ffb88fc75d57f92a8b33b39f62645fc26fedd (patch) | |
tree | 8c64b48a1a83df7f6ef68aaa46ff98b08acdbcb5 | |
parent | e23d4b9a82581f3cf1118e31d077fc9cdaff7573 (diff) |
Don't scan when touching the current selection
-rw-r--r-- | ext/fg/js/frontend.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index bd652f3b..fa0d2086 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -172,7 +172,12 @@ class Frontend { return; } - this.setPrimaryTouch(this.getPrimaryTouch(e.changedTouches)); + let touch = this.getPrimaryTouch(e.changedTouches); + if (this.selectionContainsPoint(window.getSelection(), touch.clientX, touch.clientY)) { + touch = null; + } + + this.setPrimaryTouch(touch); } onTouchEnd(e) { @@ -452,6 +457,18 @@ class Frontend { search(); } + + selectionContainsPoint(selection, x, y) { + for (let i = 0; i < selection.rangeCount; ++i) { + const range = selection.getRangeAt(i); + for (const rect of range.getClientRects()) { + if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) { + return true; + } + } + } + return false; + } } window.yomichan_frontend = new Frontend(); |