summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-17 10:09:48 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-17 10:09:48 -0700
commit5476c100467e31d7dac02a4b1c14e62a4e9b34d0 (patch)
treee817af08681c24c2c4262589e5e26cb75c4ea403 /ext
parent9280985306f5a9c79b9bd2c4daea596a5ec78ae5 (diff)
more improvements to automatic search result hiding (#71)
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/options.js2
-rw-r--r--ext/fg/js/frontend.js23
-rw-r--r--ext/fg/js/popup.js15
3 files changed, 25 insertions, 15 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index a245da80..36ab7694 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -147,7 +147,7 @@ function optionsSetDefaults(options) {
selectText: true,
alphanumeric: true,
autoHideResults: false,
- delay: 15,
+ delay: 20,
length: 10,
modifier: 'shift'
},
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index e4035289..63cdc25e 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);
}
@@ -169,19 +168,15 @@ class Frontend {
}
async searchAt(point) {
+ if (this.pendingLookup || this.popup.containsPoint(point)) {
+ return;
+ }
+
const textSource = docRangeFromPoint(point);
- let hideResults = false;
+ let hideResults = !textSource || !textSource.containsPoint(point);
try {
- if (this.pendingLookup) {
- return;
- }
-
- if (this.textSourceLast && this.textSourceLast.equals(textSource)) {
- return;
- }
-
- if (textSource && textSource.containsPoint(point)) {
+ if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) {
this.pendingLookup = true;
hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource);
}
@@ -194,10 +189,10 @@ class Frontend {
this.onError(e);
}
} finally {
- docImposterDestroy();
-
if (hideResults && this.options.scanning.autoHideResults) {
- this.popup.hide();
+ this.searchClear();
+ } else {
+ docImposterDestroy();
}
this.pendingLookup = false;
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 03958832..d1009fe9 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -100,6 +100,21 @@ class Popup {
return this.injected && this.container.style.visibility !== 'hidden';
}
+ containsPoint(point) {
+ if (!this.isVisible()) {
+ return false;
+ }
+
+ const rect = this.container.getBoundingClientRect();
+ const contained =
+ point.x >= rect.left &&
+ point.y >= rect.top &&
+ point.x < rect.right &&
+ point.y < rect.bottom;
+
+ return contained;
+ }
+
async termsShow(elementRect, definitions, options, context) {
await this.show(elementRect, options);
this.invokeApi('termsShow', {definitions, options, context});