aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/query-parser.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-05 21:43:19 -0400
committerGitHub <noreply@github.com>2020-09-05 21:43:19 -0400
commit2f8408ffcc0be1321bcd105e7675a1210b8f7df8 (patch)
treeee64b9b3ea3914f18ab7680f2eb23b53435aba39 /ext/bg/js/query-parser.js
parentdd8e32e7c40011de95e6c81211e2b434be2fde78 (diff)
Text scanner refactor (#771)
* Create searchAt wrappers * Add optional support for searching on the click event * Update QueryParser to use TextScanner's searchOnClick functionality * Move/rename searchAt * Move pendingLookup checks * Add 'searched' event to TextScanner * Use common searched event for Frontend and QueryParser * Move functions, make private
Diffstat (limited to 'ext/bg/js/query-parser.js')
-rw-r--r--ext/bg/js/query-parser.js29
1 files changed, 12 insertions, 17 deletions
diff --git a/ext/bg/js/query-parser.js b/ext/bg/js/query-parser.js
index b0ef2d78..a2a04606 100644
--- a/ext/bg/js/query-parser.js
+++ b/ext/bg/js/query-parser.js
@@ -36,15 +36,18 @@ class QueryParser extends EventDispatcher {
node: this._queryParser,
ignoreElements: () => [],
ignorePoint: null,
- search: this._search.bind(this),
- documentUtil
+ getOptionsContext,
+ documentUtil,
+ searchTerms: true,
+ searchKanji: false,
+ searchOnClick: true
});
}
async prepare() {
await this._queryParserGenerator.prepare();
this._textScanner.prepare();
- this._queryParser.addEventListener('click', this._onClick.bind(this));
+ this._textScanner.on('searched', this._onSearched.bind(this));
}
setOptions({selectedParser, termSpacing, scanning}) {
@@ -76,18 +79,12 @@ class QueryParser extends EventDispatcher {
// Private
- _onClick(e) {
- this._textScanner.searchAt(e.clientX, e.clientY, 'click');
- }
-
- async _search(textSource, cause) {
- if (textSource === null) { return null; }
-
- const optionsContext = this._getOptionsContext();
- const results = await this._textScanner.findTerms(textSource, optionsContext);
- if (results === null) { return null; }
-
- const {definitions, sentence, type} = results;
+ _onSearched({type, definitions, sentence, cause, textSource, optionsContext, error}) {
+ if (error !== null) {
+ yomichan.logError(error);
+ return;
+ }
+ if (type === null) { return; }
this.trigger('searched', {
type,
@@ -97,8 +94,6 @@ class QueryParser extends EventDispatcher {
textSource,
optionsContext
});
-
- return {definitions, type};
}
_onParserChange(e) {