diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-04-07 20:51:05 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-04-07 20:51:05 -0700 |
commit | edbb8086bc834b837268d10a54371a0247d99827 (patch) | |
tree | 67aa40596f7f135581b83a6bd4793feebadb3b0c /ext/fg | |
parent | fb46421737bdd9bbfb04542369526055e86f8905 (diff) |
Optimization
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/client.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index d5ad0c2f..56d43c3e 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -19,8 +19,9 @@ class Client { constructor() { - this.popupOffset = 10; this.lastMosePos = null; + this.popupText = ''; + this.popupOffset = 10; this.enabled = false; this.options = null; @@ -93,7 +94,12 @@ class Client { return; } - findTerm(range.toString(), ({results, length}) => { + const text = range.toString(); + if (text === this.popupText) { + return; + } + + findTerm(text, ({results, length}) => { if (length === 0) { this.hidePopup(); } else { @@ -113,17 +119,22 @@ class Client { const pos = getPopupPositionForRange(this.popup, range, this.popupOffset); + this.popupText = range.toString(); this.popup.style.left = pos.x + 'px'; this.popup.style.top = pos.y + 'px'; this.popup.style.visibility = 'visible'; } hidePopup() { - if (this.popup.style.visibility !== 'hidden') { - const selection = window.getSelection(); - selection.removeAllRanges(); - this.popup.style.visibility = 'hidden'; + if (this.popup.style.visibility === 'hidden') { + return; } + + const selection = window.getSelection(); + selection.removeAllRanges(); + + this.popupText = ''; + this.popup.style.visibility = 'hidden'; } setEnabled(enabled) { |