From 3949db26d778bc3f593438211b148e8309921542 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 8 May 2020 19:05:50 -0400 Subject: 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 --- ext/bg/js/search-query-parser.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ext/bg/js') 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; } -- cgit v1.2.3