diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-11-12 20:32:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-12 20:32:46 -0500 |
commit | f2ad94e54f2a110bf93aebfae33c808c497005be (patch) | |
tree | 82580173f795f09e40fbc47f0e8877e24b751160 /ext/mixed/js/display.js | |
parent | 219dfb4917f5b19da19b85ff223de663db561fe7 (diff) |
Text scanning options propagation (#1020)
* Update Display.setOptionsContext to update options
* Update how options context is updated in Popup
* Omit optionsContext for some _showPopupContent calls
* Remove extension unload
* Disable modifier keys in frontend's options context
* Update how text scanner passes modifiers to options context
* Update how options context is passed to display
* Update how display uses options context
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r-- | ext/mixed/js/display.js | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index d061859e..0d3ee69d 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -227,8 +227,9 @@ class Display extends EventDispatcher { return this._optionsContext; } - setOptionsContext(optionsContext) { + async setOptionsContext(optionsContext) { this._optionsContext = optionsContext; + await this.updateOptions(); } async updateOptions() { @@ -507,7 +508,7 @@ class Display extends EventDispatcher { } } - _onQueryParserSearch({type, definitions, sentence, inputInfo: {cause}, textSource}) { + _onQueryParserSearch({type, definitions, sentence, inputInfo: {cause}, textSource, optionsContext}) { const query = textSource.text(); const history = (cause === 'click'); const details = { @@ -516,7 +517,7 @@ class Display extends EventDispatcher { params: this._createSearchParams(type, query, false), state: { sentence, - url: window.location.href + optionsContext }, content: { definitions @@ -570,7 +571,7 @@ class Display extends EventDispatcher { state: { focusEntry: 0, sentence: state.sentence, - url: state.url + optionsContext: state.optionsContext }, content: { definitions @@ -629,7 +630,7 @@ class Display extends EventDispatcher { state: { focusEntry: 0, sentence, - url: state.url + optionsContext: state.optionsContext }, content: { definitions @@ -779,8 +780,7 @@ class Display extends EventDispatcher { } } - async _findDefinitions(isTerms, source, urlSearchParams) { - const optionsContext = this.getOptionsContext(); + async _findDefinitions(isTerms, source, urlSearchParams, optionsContext) { if (isTerms) { const findDetails = {}; if (urlSearchParams.get('wildcards') !== 'off') { @@ -821,6 +821,16 @@ class Display extends EventDispatcher { changeHistory = true; } + let {sentence=null, optionsContext=null, focusEntry=null, scrollX=null, scrollY=null} = state; + if (!(typeof optionsContext === 'object' && optionsContext !== null)) { + optionsContext = this.getOptionsContext(); + state.optionsContext = optionsContext; + changeHistory = true; + } + let {url} = optionsContext; + if (typeof url !== 'string') { url = window.location.href; } + sentence = this._getValidSentenceData(sentence); + source = this.postProcessQuery(source); let full = urlSearchParams.get('full'); full = (full === null ? source : this.postProcessQuery(full)); @@ -829,12 +839,15 @@ class Display extends EventDispatcher { let {definitions} = content; if (!Array.isArray(definitions)) { - definitions = await this._findDefinitions(isTerms, source, urlSearchParams); + definitions = await this._findDefinitions(isTerms, source, urlSearchParams, optionsContext); if (this._setContentToken !== token) { return true; } content.definitions = definitions; changeHistory = true; } + await this._setOptionsContextIfDifferent(optionsContext); + if (this._setContentToken !== token) { return true; } + if (changeHistory) { this._historyStateUpdate(state, content); } @@ -843,10 +856,6 @@ class Display extends EventDispatcher { eventArgs.content = content; this.trigger('contentUpdating', eventArgs); - let {sentence=null, url=null, focusEntry=null, scrollX=null, scrollY=null} = state; - if (typeof url !== 'string') { url = window.location.href; } - sentence = this._getValidSentenceData(sentence); - this._definitions = definitions; for (const definition of definitions) { @@ -1486,4 +1495,9 @@ class Display extends EventDispatcher { } return true; } + + async _setOptionsContextIfDifferent(optionsContext) { + if (deepEqual(this._optionsContext, optionsContext)) { return; } + await this.setOptionsContext(optionsContext); + } } |