aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/text-scanner.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-08 18:52:23 -0400
committerGitHub <noreply@github.com>2020-09-08 18:52:23 -0400
commitc1b16cebe7744b5d98b8e109bb3235676a79f474 (patch)
treeb569740a044f68cae069a569d7be7cb0e4393ef6 /ext/mixed/js/text-scanner.js
parent5af3c680e4b92509e95cf375eb34bddd24fd34f2 (diff)
Refactor how TextScanner's public search() function is used (#787)
Diffstat (limited to 'ext/mixed/js/text-scanner.js')
-rw-r--r--ext/mixed/js/text-scanner.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index 0e295585..12e89091 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -79,10 +79,6 @@ class TextScanner extends EventDispatcher {
this._ignoreNodes = value;
}
- get causeCurrent() {
- return this._causeCurrent;
- }
-
prepare() {
this._isPrepared = true;
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 sentence = null;
let type = null;
@@ -214,8 +224,6 @@ class TextScanner extends EventDispatcher {
});
}
- // Private
-
_onMouseOver(e) {
if (this._ignoreElements().includes(e.target)) {
this._scanTimerClear();
@@ -472,7 +480,7 @@ class TextScanner extends EventDispatcher {
const textSource = this._documentUtil.getRangeFromPoint(x, y, this._deepContentScan);
try {
- await this.search(textSource, cause);
+ await this._search(textSource, cause);
} finally {
if (textSource !== null) {
textSource.cleanup();