diff options
author | Alex Yatskov <FooSoft@users.noreply.github.com> | 2019-08-17 14:12:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-17 14:12:11 -0700 |
commit | 9ec711b780bf3ee2390a52502b293e89158cb53c (patch) | |
tree | 02a8ab47da3337d03fd72de5172c20181df2a630 /ext/fg/js | |
parent | 8ebac935e8c0ee167514d5726b1e2e16921e4957 (diff) | |
parent | cd1f367798678800a8ed7f6658362b2cbd95a632 (diff) |
Merge pull request #176 from toasted-nutbread/selection-touch-scan-disable
Don't scan when touching the current selection
Diffstat (limited to 'ext/fg/js')
-rw-r--r-- | ext/fg/js/frontend.js | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 25dd38e1..3c5f2ac8 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) { @@ -289,7 +294,8 @@ class Frontend { if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) { searched = true; this.pendingLookup = true; - hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource); + const focus = (type === 'mouse'); + hideResults = !await this.searchTerms(textSource, focus) && !await this.searchKanji(textSource, focus); success = true; } } catch (e) { @@ -312,7 +318,7 @@ class Frontend { } } - async searchTerms(textSource) { + async searchTerms(textSource, focus) { textSource.setEndOffset(this.options.scanning.length); const {definitions, length} = await apiTermsFind(textSource.text()); @@ -328,7 +334,7 @@ class Frontend { textSource.getRect(), definitions, this.options, - {sentence, url} + {sentence, url, focus} ); this.textSourceLast = textSource; @@ -339,7 +345,7 @@ class Frontend { return true; } - async searchKanji(textSource) { + async searchKanji(textSource, focus) { textSource.setEndOffset(1); const definitions = await apiKanjiFind(textSource.text()); @@ -353,7 +359,7 @@ class Frontend { textSource.getRect(), definitions, this.options, - {sentence, url} + {sentence, url, focus} ); this.textSourceLast = textSource; @@ -456,6 +462,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(); |