Don't pass null textSource into searchSource

This commit is contained in:
toasted-nutbread 2019-10-24 20:01:04 -04:00
parent 185963899b
commit dcb6f68826
2 changed files with 17 additions and 7 deletions

View File

@ -158,9 +158,14 @@ class SettingsPopupPreview {
const range = document.createRange(); const range = document.createRange();
range.selectNode(textNode); range.selectNode(textNode);
const source = new TextSourceRange(range, range.toString(), null); const source = new TextSourceRange(range, range.toString(), null);
if (source === null) { return; }
this.frontend.textSourceLast = null; this.frontend.textSourceLast = null;
try {
await this.frontend.searchSource(source, 'script'); await this.frontend.searchSource(source, 'script');
} finally {
source.cleanup();
}
await this.frontend.lastShowPromise; await this.frontend.lastShowPromise;
if (this.frontend.popup.isVisible()) { if (this.frontend.popup.isVisible()) {

View File

@ -319,19 +319,27 @@ class Frontend {
} }
const textSource = docRangeFromPoint(x, y, this.options); const textSource = docRangeFromPoint(x, y, this.options);
if (textSource === null) {
return;
}
try {
return await this.searchSource(textSource, cause); return await this.searchSource(textSource, cause);
} finally {
textSource.cleanup();
}
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} }
} }
async searchSource(textSource, cause) { async searchSource(textSource, cause) {
let hideResults = textSource === null; let hideResults = false;
let searched = false; let searched = false;
let success = false; let success = false;
try { try {
if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) { if (!this.textSourceLast || !this.textSourceLast.equals(textSource)) {
searched = true; searched = true;
this.pendingLookup = true; this.pendingLookup = true;
const focus = (cause === 'mouse'); const focus = (cause === 'mouse');
@ -351,9 +359,6 @@ class Frontend {
this.onError(e); this.onError(e);
} }
} finally { } finally {
if (textSource !== null) {
textSource.cleanup();
}
if (hideResults && this.options.scanning.autoHideResults) { if (hideResults && this.options.scanning.autoHideResults) {
this.searchClear(true); this.searchClear(true);
} }