aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/frontend.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/frontend.js')
-rw-r--r--ext/fg/js/frontend.js38
1 files changed, 16 insertions, 22 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 41c93f00..3a90b3ad 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -80,7 +80,6 @@ class Frontend {
const search = async () => {
try {
await this.searchAt({x: e.clientX, y: e.clientY});
- this.pendingLookup = false;
} catch (e) {
this.onError(e);
}
@@ -153,7 +152,7 @@ class Frontend {
}
onError(error) {
- window.alert(`Error: ${error}`);
+ window.alert(`Error: ${error.toString ? error.toString() : error}`);
}
popupTimerSet(callback) {
@@ -169,27 +168,17 @@ class Frontend {
}
async searchAt(point) {
- let textSource = null;
-
- try {
- if (this.pendingLookup) {
- return;
- }
-
- textSource = docRangeFromPoint(point);
- if (!textSource || !textSource.containsPoint(point)) {
- docImposterDestroy();
- return;
- }
-
- if (this.textSourceLast && this.textSourceLast.equals(textSource)) {
- return;
- }
+ if (this.pendingLookup || this.popup.containsPoint(point)) {
+ return;
+ }
- this.pendingLookup = true;
+ const textSource = docRangeFromPoint(point);
+ let hideResults = !textSource || !textSource.containsPoint(point);
- if (!await this.searchTerms(textSource)) {
- await this.searchKanji(textSource);
+ try {
+ if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) {
+ this.pendingLookup = true;
+ hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource);
}
} catch (e) {
if (window.yomichan_orphaned) {
@@ -200,7 +189,12 @@ class Frontend {
this.onError(e);
}
} finally {
- docImposterDestroy();
+ if (hideResults && this.options.scanning.autoHideResults) {
+ this.searchClear();
+ } else {
+ docImposterDestroy();
+ }
+
this.pendingLookup = false;
}
}