From 710ffb88fc75d57f92a8b33b39f62645fc26fedd Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 9 Aug 2019 21:45:29 -0400 Subject: Don't scan when touching the current selection --- ext/fg/js/frontend.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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(); -- cgit v1.2.3 From 345b9c6f9dc336265f4ef8cd67cc2beb57abe354 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 9 Aug 2019 22:29:14 -0400 Subject: Disable focus of popup when using touch Context menu on Firefox will not target the text properly if the focus is on the popup window. --- ext/fg/js/frontend.js | 11 ++++++----- ext/mixed/js/display.js | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index fa0d2086..83fd9aff 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -290,7 +290,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) { @@ -313,7 +314,7 @@ class Frontend { } } - async searchTerms(textSource) { + async searchTerms(textSource, focus) { textSource.setEndOffset(this.options.scanning.length); const {definitions, length} = await apiTermsFind(textSource.text()); @@ -329,7 +330,7 @@ class Frontend { textSource.getRect(), definitions, this.options, - {sentence, url} + {sentence, url, focus} ); this.textSourceLast = textSource; @@ -340,7 +341,7 @@ class Frontend { return true; } - async searchKanji(textSource) { + async searchKanji(textSource, focus) { textSource.setEndOffset(1); const definitions = await apiKanjiFind(textSource.text()); @@ -354,7 +355,7 @@ class Frontend { textSource.getRect(), definitions, this.options, - {sentence, url} + {sentence, url, focus} ); this.textSourceLast = textSource; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 3bb78fe1..5bd57159 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -269,7 +269,9 @@ class Display { async termsShow(definitions, options, context) { try { - window.focus(); + if (context && context.focus) { + window.focus(); + } this.definitions = definitions; this.options = options; @@ -321,7 +323,9 @@ class Display { async kanjiShow(definitions, options, context) { try { - window.focus(); + if (context && context.focus) { + window.focus(); + } this.definitions = definitions; this.options = options; -- cgit v1.2.3 From cd1f367798678800a8ed7f6658362b2cbd95a632 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 16 Aug 2019 17:36:55 -0400 Subject: Focus if context is falsy or focus field isn't false --- ext/mixed/js/display.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 5bd57159..8901ba71 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -269,7 +269,7 @@ class Display { async termsShow(definitions, options, context) { try { - if (context && context.focus) { + if (!context || context.focus !== false) { window.focus(); } @@ -323,7 +323,7 @@ class Display { async kanjiShow(definitions, options, context) { try { - if (context && context.focus) { + if (!context || context.focus !== false) { window.focus(); } -- cgit v1.2.3