diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-07-26 19:29:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-26 19:29:12 -0400 |
commit | 313476aa926797a0072b42c1dc6a12677f34551c (patch) | |
tree | 62df864195f6256b468626b5f735ab72583318e8 /ext/bg | |
parent | 0512258c8e77f4ee63a7f7d100e8bb7c898fc343 (diff) |
Query parser fix (#695)
* Standardize setContent calls
* Rename _queryText to _fullQuery
* Move query parser into Display and update float.html
* Generalize params
* Add "full" parameter to maintain the original full query
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/search.js | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 49a93e47..fc857368 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -19,7 +19,6 @@ * ClipboardMonitor * DOM * Display - * QueryParser * api * wanakana */ @@ -33,16 +32,11 @@ class DisplaySearch extends Display { this._intro = document.querySelector('#intro'); this._clipboardMonitorEnable = document.querySelector('#clipboard-monitor-enable'); this._wanakanaEnable = document.querySelector('#wanakana-enable'); - this._queryText = ''; this._introVisible = true; this._introAnimationTimer = null; this._clipboardMonitor = new ClipboardMonitor({ getClipboard: api.clipboardGet.bind(api) }); - this._queryParser = new QueryParser({ - getOptionsContext: this.getOptionsContext.bind(this), - setSpinnerVisible: this.setSpinnerVisible.bind(this) - }); this._onKeyDownIgnoreKeys = new Map([ ['ANY_MOD', new Set([ 'Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'PageDown', 'PageUp', 'Home', 'End', @@ -66,9 +60,7 @@ class DisplaySearch extends Display { await super.prepare(); await this.updateOptions(); yomichan.on('optionsUpdated', () => this.updateOptions()); - await this._queryParser.prepare(); - this._queryParser.on('searched', this._onQueryParserSearch.bind(this)); this.on('contentUpdating', this._onContentUpdating.bind(this)); this.setHistorySettings({useBrowserHistory: true}); @@ -152,8 +144,6 @@ class DisplaySearch extends Display { async updateOptions() { await super.updateOptions(); - const options = this.getOptions(); - this._queryParser.setOptions(options); if (!this._isPrepared) { return; } const query = this._query.value; if (query) { @@ -164,7 +154,7 @@ class DisplaySearch extends Display { // Private - _onContentUpdating({type, source, content}) { + _onContentUpdating({type, source, content, urlSearchParams}) { let animate = false; let valid = false; switch (type) { @@ -180,33 +170,19 @@ class DisplaySearch extends Display { source = ''; break; } + if (typeof source !== 'string') { source = ''; } + + let full = urlSearchParams.get('full'); + if (full === null) { full = source; } + this._closePopups(); - this._setQuery(source); + this._setQuery(full); this._setIntroVisible(!valid, animate); this._setTitleText(source); this._updateSearchButton(); } - _onQueryParserSearch({type, definitions, sentence, cause, textSource}) { - this.setContent({ - focus: false, - history: cause !== 'mouse', - params: { - type, - query: textSource.text(), - wildcards: 'off' - }, - state: { - sentence, - url: window.location.href - }, - content: { - definitions - } - }); - } - _onSearchInput() { this._updateSearchButton(); @@ -243,7 +219,7 @@ class DisplaySearch extends Display { } _onSearchQueryUpdated(query, animate) { - this.setContent({ + const details = { focus: false, history: false, params: { @@ -258,7 +234,8 @@ class DisplaySearch extends Display { definitions: null, animate } - }); + }; + this.setContent(details); } _onWanakanaEnableChange(e) { @@ -321,10 +298,8 @@ class DisplaySearch extends Display { // NOP } } - if (this._queryText === interpretedQuery) { return; } - this._queryText = interpretedQuery; this._query.value = interpretedQuery; - this._queryParser.setText(interpretedQuery); + this.setQueryParserText(interpretedQuery); } _setIntroVisible(visible, animate) { |