summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-08 19:05:50 -0400
committerGitHub <noreply@github.com>2020-05-08 19:05:50 -0400
commit3949db26d778bc3f593438211b148e8309921542 (patch)
tree7a93fdc9d4a58de8c29acaefa0e5f7eeddd2a5b3 /ext/bg
parentb936c3e4b1bc993e535b02dee91bf6afc15a3564 (diff)
Text scanner refactor (#517)
* Fix return type * Pass search function as a constructor argument * Pass constructor as a details object For consistency with other complex constructors and improved semantics. * Convert _ignorePoints to a single optional function * Organize functions * Rename ignorePoints to ignorePoint
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/search-query-parser.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js
index caace34b..e1e37d1c 100644
--- a/ext/bg/js/search-query-parser.js
+++ b/ext/bg/js/search-query-parser.js
@@ -34,12 +34,12 @@ class QueryParser {
this._queryParser = document.querySelector('#query-parser-content');
this._queryParserSelect = document.querySelector('#query-parser-select-container');
this._queryParserGenerator = new QueryParserGenerator();
- this._textScanner = new TextScanner(
- this._queryParser,
- () => [],
- []
- );
- this._textScanner.onSearchSource = this._onSearchSource.bind(this);
+ this._textScanner = new TextScanner({
+ node: this._queryParser,
+ ignoreElements: () => [],
+ ignorePoint: null,
+ search: this._search.bind(this)
+ });
}
async prepare() {
@@ -74,11 +74,11 @@ class QueryParser {
this._textScanner.searchAt(e.clientX, e.clientY, 'click');
}
- async _onSearchSource(textSource, cause) {
+ async _search(textSource, cause) {
if (textSource === null) { return null; }
const searchText = this._textScanner.getTextSourceContent(textSource, this._options.scanning.length);
- if (searchText.length === 0) { return; }
+ if (searchText.length === 0) { return null; }
const {definitions, length} = await apiTermsFind(searchText, {}, this._getOptionsContext());
if (definitions.length === 0) { return null; }