Merge pull request #176 from toasted-nutbread/selection-touch-scan-disable
Don't scan when touching the current selection
This commit is contained in:
commit
9ec711b780
@ -172,7 +172,12 @@ class Frontend {
|
|||||||
return;
|
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) {
|
onTouchEnd(e) {
|
||||||
@ -289,7 +294,8 @@ class Frontend {
|
|||||||
if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) {
|
if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) {
|
||||||
searched = true;
|
searched = true;
|
||||||
this.pendingLookup = 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;
|
success = true;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -312,7 +318,7 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchTerms(textSource) {
|
async searchTerms(textSource, focus) {
|
||||||
textSource.setEndOffset(this.options.scanning.length);
|
textSource.setEndOffset(this.options.scanning.length);
|
||||||
|
|
||||||
const {definitions, length} = await apiTermsFind(textSource.text());
|
const {definitions, length} = await apiTermsFind(textSource.text());
|
||||||
@ -328,7 +334,7 @@ class Frontend {
|
|||||||
textSource.getRect(),
|
textSource.getRect(),
|
||||||
definitions,
|
definitions,
|
||||||
this.options,
|
this.options,
|
||||||
{sentence, url}
|
{sentence, url, focus}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.textSourceLast = textSource;
|
this.textSourceLast = textSource;
|
||||||
@ -339,7 +345,7 @@ class Frontend {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchKanji(textSource) {
|
async searchKanji(textSource, focus) {
|
||||||
textSource.setEndOffset(1);
|
textSource.setEndOffset(1);
|
||||||
|
|
||||||
const definitions = await apiKanjiFind(textSource.text());
|
const definitions = await apiKanjiFind(textSource.text());
|
||||||
@ -353,7 +359,7 @@ class Frontend {
|
|||||||
textSource.getRect(),
|
textSource.getRect(),
|
||||||
definitions,
|
definitions,
|
||||||
this.options,
|
this.options,
|
||||||
{sentence, url}
|
{sentence, url, focus}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.textSourceLast = textSource;
|
this.textSourceLast = textSource;
|
||||||
@ -456,6 +462,18 @@ class Frontend {
|
|||||||
|
|
||||||
search();
|
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();
|
window.yomichan_frontend = new Frontend();
|
||||||
|
@ -272,7 +272,9 @@ class Display {
|
|||||||
|
|
||||||
async termsShow(definitions, options, context) {
|
async termsShow(definitions, options, context) {
|
||||||
try {
|
try {
|
||||||
window.focus();
|
if (!context || context.focus !== false) {
|
||||||
|
window.focus();
|
||||||
|
}
|
||||||
|
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -324,7 +326,9 @@ class Display {
|
|||||||
|
|
||||||
async kanjiShow(definitions, options, context) {
|
async kanjiShow(definitions, options, context) {
|
||||||
try {
|
try {
|
||||||
window.focus();
|
if (!context || context.focus !== false) {
|
||||||
|
window.focus();
|
||||||
|
}
|
||||||
|
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
Loading…
Reference in New Issue
Block a user