more improvements to automatic search result hiding (#71)

This commit is contained in:
Alex Yatskov 2017-09-17 10:09:48 -07:00
parent 9280985306
commit 5476c10046
3 changed files with 25 additions and 15 deletions

View File

@ -147,7 +147,7 @@ function optionsSetDefaults(options) {
selectText: true, selectText: true,
alphanumeric: true, alphanumeric: true,
autoHideResults: false, autoHideResults: false,
delay: 15, delay: 20,
length: 10, length: 10,
modifier: 'shift' modifier: 'shift'
}, },

View File

@ -80,7 +80,6 @@ class Frontend {
const search = async () => { const search = async () => {
try { try {
await this.searchAt({x: e.clientX, y: e.clientY}); await this.searchAt({x: e.clientX, y: e.clientY});
this.pendingLookup = false;
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} }
@ -169,19 +168,15 @@ class Frontend {
} }
async searchAt(point) { async searchAt(point) {
if (this.pendingLookup || this.popup.containsPoint(point)) {
return;
}
const textSource = docRangeFromPoint(point); const textSource = docRangeFromPoint(point);
let hideResults = false; let hideResults = !textSource || !textSource.containsPoint(point);
try { try {
if (this.pendingLookup) { if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) {
return;
}
if (this.textSourceLast && this.textSourceLast.equals(textSource)) {
return;
}
if (textSource && textSource.containsPoint(point)) {
this.pendingLookup = true; this.pendingLookup = true;
hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource); hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource);
} }
@ -194,10 +189,10 @@ class Frontend {
this.onError(e); this.onError(e);
} }
} finally { } finally {
docImposterDestroy();
if (hideResults && this.options.scanning.autoHideResults) { if (hideResults && this.options.scanning.autoHideResults) {
this.popup.hide(); this.searchClear();
} else {
docImposterDestroy();
} }
this.pendingLookup = false; this.pendingLookup = false;

View File

@ -100,6 +100,21 @@ class Popup {
return this.injected && this.container.style.visibility !== 'hidden'; 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) { async termsShow(elementRect, definitions, options, context) {
await this.show(elementRect, options); await this.show(elementRect, options);
this.invokeApi('termsShow', {definitions, options, context}); this.invokeApi('termsShow', {definitions, options, context});