Refactor how TextScanner's public search() function is used (#787)
This commit is contained in:
parent
5af3c680e4
commit
c1b16cebe7
@ -129,7 +129,7 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setTextSource(textSource) {
|
async setTextSource(textSource) {
|
||||||
await this._textScanner.search(textSource, 'script');
|
await this._textScanner.search(textSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOptionsContext() {
|
async getOptionsContext() {
|
||||||
@ -299,11 +299,7 @@ class Frontend {
|
|||||||
|
|
||||||
this._updateContentScale();
|
this._updateContentScale();
|
||||||
|
|
||||||
const textSourceCurrent = this._textScanner.getCurrentTextSource();
|
await this._textScanner.searchLast();
|
||||||
const causeCurrent = this._textScanner.causeCurrent;
|
|
||||||
if (textSourceCurrent !== null && causeCurrent !== null) {
|
|
||||||
await this._textScanner.search(textSourceCurrent, causeCurrent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _updatePopup() {
|
async _updatePopup() {
|
||||||
|
@ -79,10 +79,6 @@ class TextScanner extends EventDispatcher {
|
|||||||
this._ignoreNodes = value;
|
this._ignoreNodes = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
get causeCurrent() {
|
|
||||||
return this._causeCurrent;
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
this._isPrepared = true;
|
this._isPrepared = true;
|
||||||
this.setEnabled(this._enabled);
|
this.setEnabled(this._enabled);
|
||||||
@ -174,7 +170,21 @@ class TextScanner extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(textSource, cause) {
|
async searchLast() {
|
||||||
|
if (this._textSourceCurrent !== null && this._causeCurrent !== null) {
|
||||||
|
await this._search(this._textSourceCurrent, this._causeCurrent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async search(textSource) {
|
||||||
|
return await this._search(textSource, 'script');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private
|
||||||
|
|
||||||
|
async _search(textSource, cause) {
|
||||||
let definitions = null;
|
let definitions = null;
|
||||||
let sentence = null;
|
let sentence = null;
|
||||||
let type = null;
|
let type = null;
|
||||||
@ -214,8 +224,6 @@ class TextScanner extends EventDispatcher {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
|
||||||
|
|
||||||
_onMouseOver(e) {
|
_onMouseOver(e) {
|
||||||
if (this._ignoreElements().includes(e.target)) {
|
if (this._ignoreElements().includes(e.target)) {
|
||||||
this._scanTimerClear();
|
this._scanTimerClear();
|
||||||
@ -472,7 +480,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
|
|
||||||
const textSource = this._documentUtil.getRangeFromPoint(x, y, this._deepContentScan);
|
const textSource = this._documentUtil.getRangeFromPoint(x, y, this._deepContentScan);
|
||||||
try {
|
try {
|
||||||
await this.search(textSource, cause);
|
await this._search(textSource, cause);
|
||||||
} finally {
|
} finally {
|
||||||
if (textSource !== null) {
|
if (textSource !== null) {
|
||||||
textSource.cleanup();
|
textSource.cleanup();
|
||||||
|
Loading…
Reference in New Issue
Block a user