From 4a43b41f79d46b8a677bbfb11c27d43e126e670f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 25 Jul 2020 09:58:06 -0400 Subject: Set content refactor (#686) * Simplify invoke * Pass isTerms instead of type * Update DisplaySearch.setContent to pass argument array * Simplify argument object structure for setContent * Move focus and disableHistory level * Always include focus and disableHistory options * Change disableHistory to history * Pass source text to setContent * Use consistent argument/object field order * Remove unused previous field * Combine logic for forward/back navigation --- ext/bg/js/search.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index b3e3ebca..93f45468 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -158,10 +158,10 @@ class DisplaySearch extends Display { } } - async setContent(type, details) { + async setContent(...args) { this._query.blur(); this._closePopups(); - return await super.setContent(type, details); + return await super.setContent(...args); } clearContent() { @@ -171,12 +171,14 @@ class DisplaySearch extends Display { // Private - _onQueryParserSearch({type, definitions, sentence, cause}) { - this.setContent(type, { + _onQueryParserSearch({type, definitions, sentence, cause, textSource}) { + this.setContent({ + focus: false, + history: cause !== 'mouse', + type, + source: textSource.text(), definitions, context: { - focus: false, - disableHistory: cause === 'mouse', sentence, url: window.location.href } @@ -254,12 +256,17 @@ class DisplaySearch extends Display { this._updateSearchButton(); if (valid) { const {definitions} = await api.termsFind(query, details, this.getOptionsContext()); - this.setContent('terms', {definitions, context: { + this.setContent({ focus: false, - disableHistory: true, - sentence: {text: query, offset: 0}, - url: window.location.href - }}); + history: false, + definitions, + source: query, + type: 'terms', + context: { + sentence: {text: query, offset: 0}, + url: window.location.href + } + }); } else { this.clearContent(); } -- cgit v1.2.3