aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/text-scanner.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-11 23:13:35 -0500
committerGitHub <noreply@github.com>2021-01-11 23:13:35 -0500
commit983e2c79361ad15ada6aae0d153fef9f1b867a93 (patch)
tree1b655b205cdc062f44248b0f0c9ef13d3ca85266 /ext/mixed/js/text-scanner.js
parent5e87a490f78888717c58491959745431580bd64e (diff)
Refactor text scanner options context generation (#1225)
* Refactor how options context is created and updated * Udpate TextScanner/QueryParser to use getSearchContext instead of getOptionsContext
Diffstat (limited to 'ext/mixed/js/text-scanner.js')
-rw-r--r--ext/mixed/js/text-scanner.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index 11a6f88f..98d87341 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -24,7 +24,7 @@ class TextScanner extends EventDispatcher {
constructor({
node,
documentUtil,
- getOptionsContext,
+ getSearchContext,
ignoreElements=null,
ignorePoint=null,
searchTerms=false,
@@ -35,7 +35,7 @@ class TextScanner extends EventDispatcher {
super();
this._node = node;
this._documentUtil = documentUtil;
- this._getOptionsContext = getOptionsContext;
+ this._getSearchContext = getSearchContext;
this._ignoreElements = ignoreElements;
this._ignorePoint = ignorePoint;
this._searchTerms = searchTerms;
@@ -290,8 +290,8 @@ class TextScanner extends EventDispatcher {
// Private
- async _getOptionsContextForInput(inputInfo) {
- const optionsContext = clone(await this._getOptionsContext());
+ _createOptionsContextForInput(baseOptionsContext, inputInfo) {
+ const optionsContext = clone(baseOptionsContext);
const {modifiers, modifierKeys} = inputInfo;
optionsContext.modifiers = [...modifiers];
optionsContext.modifierKeys = [...modifierKeys];
@@ -305,13 +305,16 @@ class TextScanner extends EventDispatcher {
let error = null;
let searched = false;
let optionsContext = null;
+ let detail = null;
try {
if (this._textSourceCurrent !== null && this._textSourceCurrent.hasSameStart(textSource)) {
return;
}
- optionsContext = await this._getOptionsContextForInput(inputInfo);
+ ({optionsContext, detail} = await this._getSearchContext());
+ optionsContext = this._createOptionsContextForInput(optionsContext, inputInfo);
+
searched = true;
const result = await this._findDefinitions(textSource, searchTerms, searchKanji, optionsContext);
@@ -334,6 +337,7 @@ class TextScanner extends EventDispatcher {
inputInfo,
textSource,
optionsContext,
+ detail,
error
});
}