diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-24 19:38:29 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-28 17:03:42 -0400 |
commit | 185963899b4176b31a14ab141f1335c17a2de9c4 (patch) | |
tree | 39764406e1c5b0027eab16569a99f44dc71fb833 /ext/fg/js | |
parent | d608657495d59469b17fbae9027772c26848a95e (diff) |
Use promiseTimeout
Diffstat (limited to 'ext/fg/js')
-rw-r--r-- | ext/fg/js/frontend.js | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index c8a7d254..897c7b73 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -20,7 +20,7 @@ class Frontend { constructor(popup, ignoreNodes) { this.popup = popup; - this.popupTimer = null; + this.popupTimerPromise = null; this.textSourceLast = null; this.pendingLookup = false; this.options = null; @@ -74,7 +74,7 @@ class Frontend { } onMouseOver(e) { - if (e.target === this.popup.container && this.popupTimer !== null) { + if (e.target === this.popup.container) { this.popupTimerClear(); } } @@ -99,14 +99,17 @@ class Frontend { } const search = async () => { + if (scanningModifier === 'none') { + if (!await this.popupTimerWait()) { + // Aborted + return; + } + } + await this.searchAt(e.clientX, e.clientY, 'mouse'); }; - if (scanningModifier === 'none') { - this.popupTimerSet(search); - } else { - search(); - } + search(); } onMouseDown(e) { @@ -293,19 +296,19 @@ class Frontend { await this.popup.setOptions(this.options); } - popupTimerSet(callback) { + async popupTimerWait() { const delay = this.options.scanning.delay; - if (delay > 0) { - this.popupTimer = window.setTimeout(callback, delay); - } else { - Promise.resolve().then(callback); + this.popupTimerPromise = promiseTimeout(delay, true); + try { + return await this.popupTimerPromise; + } finally { + this.popupTimerPromise = null; } } popupTimerClear() { - if (this.popupTimer !== null) { - window.clearTimeout(this.popupTimer); - this.popupTimer = null; + if (this.popupTimerPromise !== null) { + this.popupTimerPromise.resolve(false); } } |