summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-09 13:27:21 -0400
committerGitHub <noreply@github.com>2020-08-09 13:27:21 -0400
commit6da02c6eee803756d9a9075bfde333eeb31ce64b (patch)
tree158d81b89ca99095c06db31c1ebc7bb46a57c33a /ext/bg/js
parent480e0e15e3109165d077c18985893d7cca79959e (diff)
document.js refactor (#719)
* Refactor document.js into a class * Move public functions first * Rename private functions * Rename * Rename argument * Use instance of DocumentUtil * Update tests * Refactor * Rename (test-)document.js to (test-)document-util.js
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/query-parser.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/bg/js/query-parser.js b/ext/bg/js/query-parser.js
index 6ca09a82..2ad88601 100644
--- a/ext/bg/js/query-parser.js
+++ b/ext/bg/js/query-parser.js
@@ -19,11 +19,10 @@
* QueryParserGenerator
* TextScanner
* api
- * docSentenceExtract
*/
class QueryParser extends EventDispatcher {
- constructor({getOptionsContext, setSpinnerVisible}) {
+ constructor({getOptionsContext, setSpinnerVisible, documentUtil}) {
super();
this._getOptionsContext = getOptionsContext;
this._setSpinnerVisible = setSpinnerVisible;
@@ -31,6 +30,7 @@ class QueryParser extends EventDispatcher {
this._scanLength = 1;
this._sentenceExtent = 1;
this._layoutAwareScan = false;
+ this._documentUtil = documentUtil;
this._parseResults = [];
this._queryParser = document.querySelector('#query-parser-content');
this._queryParserSelect = document.querySelector('#query-parser-select-container');
@@ -39,7 +39,8 @@ class QueryParser extends EventDispatcher {
node: this._queryParser,
ignoreElements: () => [],
ignorePoint: null,
- search: this._search.bind(this)
+ search: this._search.bind(this),
+ documentUtil
});
}
@@ -104,7 +105,7 @@ class QueryParser extends EventDispatcher {
const {definitions, length} = await api.termsFind(searchText, {}, optionsContext);
if (definitions.length === 0) { return null; }
- const sentence = docSentenceExtract(textSource, sentenceExtent, layoutAwareScan);
+ const sentence = this._documentUtil.extractSentence(textSource, sentenceExtent, layoutAwareScan);
textSource.setEndOffset(length, layoutAwareScan);