Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Improve query parser scanning #1154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/bg/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class DisplaySearch extends Display {
await this.updateOptions();
const query = this._queryInput.value;
if (query) {
this._search(false, false);
this.searchLast();
}
}

Expand Down
41 changes: 39 additions & 2 deletions ext/mixed/js/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Display extends EventDispatcher {
this._contentType = 'clear';
this._defaultTitle = document.title;
this._titleMaxLength = 1000;
this._query = '';
this._rawQuery = '';
this._fullQuery = '';
this._documentUtil = new DocumentUtil();
this._progressIndicator = document.querySelector('#progress-indicator');
Expand Down Expand Up @@ -459,6 +461,31 @@ class Display extends EventDispatcher {
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

_onMessage({action, params}, sender, callback) {
Expand Down Expand Up @@ -560,6 +587,8 @@ class Display extends EventDispatcher {
let clear = true;
this._historyHasChanged = true;
this._contentType = type;
this._query = '';
this._rawQuery = '';
const eventArgs = {type, urlSearchParams, token};

// Set content
Expand All @@ -570,9 +599,11 @@ class Display extends EventDispatcher {
let query = urlSearchParams.get('query');
if (!query) { break; }

this._query = query;
clear = false;
const isTerms = (type === 'terms');
query = this.postProcessQuery(query);
this._rawQuery = query;
let queryFull = urlSearchParams.get('full');
queryFull = (queryFull !== null ? this.postProcessQuery(queryFull) : query);
const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off');
Expand Down Expand Up @@ -611,14 +642,20 @@ class Display extends EventDispatcher {

_onQueryParserSearch({type, definitions, sentence, inputInfo: {cause}, textSource, optionsContext}) {
const query = textSource.text();
const history = (cause === 'click');
const historyState = this._history.state;
const history = (
cause === 'click' ||
!isObject(historyState) ||
historyState.cause !== 'queryParser'
);
const details = {
focus: false,
history,
params: this._createSearchParams(type, query, false),
state: {
sentence,
optionsContext
optionsContext,
cause: 'queryParser'
},
content: {
definitions
Expand Down