Optimization
This commit is contained in:
parent
fb46421737
commit
edbb8086bc
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.popupOffset = 10;
|
|
||||||
this.lastMosePos = null;
|
this.lastMosePos = null;
|
||||||
|
this.popupText = '';
|
||||||
|
this.popupOffset = 10;
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
this.options = null;
|
this.options = null;
|
||||||
|
|
||||||
@ -93,7 +94,12 @@ class Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
findTerm(range.toString(), ({results, length}) => {
|
const text = range.toString();
|
||||||
|
if (text === this.popupText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
findTerm(text, ({results, length}) => {
|
||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
} else {
|
} else {
|
||||||
@ -113,18 +119,23 @@ class Client {
|
|||||||
|
|
||||||
const pos = getPopupPositionForRange(this.popup, range, this.popupOffset);
|
const pos = getPopupPositionForRange(this.popup, range, this.popupOffset);
|
||||||
|
|
||||||
|
this.popupText = range.toString();
|
||||||
this.popup.style.left = pos.x + 'px';
|
this.popup.style.left = pos.x + 'px';
|
||||||
this.popup.style.top = pos.y + 'px';
|
this.popup.style.top = pos.y + 'px';
|
||||||
this.popup.style.visibility = 'visible';
|
this.popup.style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
|
|
||||||
hidePopup() {
|
hidePopup() {
|
||||||
if (this.popup.style.visibility !== 'hidden') {
|
if (this.popup.style.visibility === 'hidden') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
|
|
||||||
|
this.popupText = '';
|
||||||
this.popup.style.visibility = 'hidden';
|
this.popup.style.visibility = 'hidden';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
setEnabled(enabled) {
|
setEnabled(enabled) {
|
||||||
if (!(this.enabled = enabled)) {
|
if (!(this.enabled = enabled)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user