Improve query parser scanning (#1154)

* Improve how the search page updates after settings have changed

* Always update the history on the first scan of the query parser
This commit is contained in:
toasted-nutbread 2020-12-21 19:19:59 -05:00 committed by GitHub
parent 9dd2a9c98e
commit 18043babeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 3 deletions

View File

@ -144,7 +144,7 @@ class DisplaySearch extends Display {
await this.updateOptions(); await this.updateOptions();
const query = this._queryInput.value; const query = this._queryInput.value;
if (query) { if (query) {
this._search(false, false); this.searchLast();
} }
} }

View File

@ -71,6 +71,8 @@ class Display extends EventDispatcher {
this._contentType = 'clear'; this._contentType = 'clear';
this._defaultTitle = document.title; this._defaultTitle = document.title;
this._titleMaxLength = 1000; this._titleMaxLength = 1000;
this._query = '';
this._rawQuery = '';
this._fullQuery = ''; this._fullQuery = '';
this._documentUtil = new DocumentUtil(); this._documentUtil = new DocumentUtil();
this._progressIndicator = document.querySelector('#progress-indicator'); this._progressIndicator = document.querySelector('#progress-indicator');
@ -459,6 +461,31 @@ class Display extends EventDispatcher {
this._updateFocusedElement(); this._updateFocusedElement();
} }
searchLast() {
const type = this._contentType;
if (type === 'clear') { return; }
const query = this._rawQuery;
const state = (
this._historyHasState() ?
clone(this._history.state) :
{
focusEntry: 0,
sentence: {text: query, offset: 0},
url: window.location.href
}
);
const details = {
focus: false,
history: false,
params: this._createSearchParams(type, query, false),
state,
content: {
definitions: null
}
};
this.setContent(details);
}
// Message handlers // Message handlers
_onMessage({action, params}, sender, callback) { _onMessage({action, params}, sender, callback) {
@ -560,6 +587,8 @@ class Display extends EventDispatcher {
let clear = true; let clear = true;
this._historyHasChanged = true; this._historyHasChanged = true;
this._contentType = type; this._contentType = type;
this._query = '';
this._rawQuery = '';
const eventArgs = {type, urlSearchParams, token}; const eventArgs = {type, urlSearchParams, token};
// Set content // Set content
@ -570,9 +599,11 @@ class Display extends EventDispatcher {
let query = urlSearchParams.get('query'); let query = urlSearchParams.get('query');
if (!query) { break; } if (!query) { break; }
this._query = query;
clear = false; clear = false;
const isTerms = (type === 'terms'); const isTerms = (type === 'terms');
query = this.postProcessQuery(query); query = this.postProcessQuery(query);
this._rawQuery = query;
let queryFull = urlSearchParams.get('full'); let queryFull = urlSearchParams.get('full');
queryFull = (queryFull !== null ? this.postProcessQuery(queryFull) : query); queryFull = (queryFull !== null ? this.postProcessQuery(queryFull) : query);
const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off'); const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off');
@ -611,14 +642,20 @@ class Display extends EventDispatcher {
_onQueryParserSearch({type, definitions, sentence, inputInfo: {cause}, textSource, optionsContext}) { _onQueryParserSearch({type, definitions, sentence, inputInfo: {cause}, textSource, optionsContext}) {
const query = textSource.text(); const query = textSource.text();
const history = (cause === 'click'); const historyState = this._history.state;
const history = (
cause === 'click' ||
!isObject(historyState) ||
historyState.cause !== 'queryParser'
);
const details = { const details = {
focus: false, focus: false,
history, history,
params: this._createSearchParams(type, query, false), params: this._createSearchParams(type, query, false),
state: { state: {
sentence, sentence,
optionsContext optionsContext,
cause: 'queryParser'
}, },
content: { content: {
definitions definitions