Fix history replacement issue (#1917)
* Remove unused "history" field of event details * Change setContent history parameter to historyMode
This commit is contained in:
parent
f565cc5a47
commit
3e7f3af63c
@ -515,7 +515,7 @@ class Frontend {
|
||||
const {url} = optionsContext;
|
||||
const details = {
|
||||
focus,
|
||||
history: false,
|
||||
historyMode: 'clear',
|
||||
params: {
|
||||
type,
|
||||
query,
|
||||
|
@ -112,7 +112,7 @@ class DisplayHistory extends EventDispatcher {
|
||||
}
|
||||
|
||||
_triggerStateChanged(synthetic) {
|
||||
this.trigger('stateChanged', {history: this, synthetic});
|
||||
this.trigger('stateChanged', {synthetic});
|
||||
}
|
||||
|
||||
_updateHistoryFromCurrent(replace) {
|
||||
|
@ -347,7 +347,8 @@ class Display extends EventDispatcher {
|
||||
}
|
||||
|
||||
setContent(details) {
|
||||
const {focus, history, params, state, content} = details;
|
||||
const {focus, params, state, content} = details;
|
||||
const historyMode = this._historyHasChanged ? details.historyMode : 'clear';
|
||||
|
||||
if (focus) {
|
||||
window.focus();
|
||||
@ -359,12 +360,18 @@ class Display extends EventDispatcher {
|
||||
}
|
||||
const url = `${location.protocol}//${location.host}${location.pathname}?${urlSearchParams.toString()}`;
|
||||
|
||||
if (history && this._historyHasChanged) {
|
||||
this._updateHistoryState();
|
||||
this._history.pushState(state, content, url);
|
||||
} else {
|
||||
switch (historyMode) {
|
||||
case 'clear':
|
||||
this._history.clear();
|
||||
this._history.replaceState(state, content, url);
|
||||
break;
|
||||
case 'overwrite':
|
||||
this._history.replaceState(state, content, url);
|
||||
break;
|
||||
default: // 'new'
|
||||
this._updateHistoryState();
|
||||
this._history.pushState(state, content, url);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,7 +437,7 @@ class Display extends EventDispatcher {
|
||||
);
|
||||
const details = {
|
||||
focus: false,
|
||||
history: false,
|
||||
historyMode: 'clear',
|
||||
params: this._createSearchParams(type, query, false),
|
||||
state,
|
||||
content: {
|
||||
@ -638,14 +645,14 @@ class Display extends EventDispatcher {
|
||||
_onQueryParserSearch({type, dictionaryEntries, sentence, inputInfo: {eventType}, textSource, optionsContext}) {
|
||||
const query = textSource.text();
|
||||
const historyState = this._history.state;
|
||||
const history = (
|
||||
const historyMode = (
|
||||
eventType === 'click' ||
|
||||
!isObject(historyState) ||
|
||||
historyState.cause !== 'queryParser'
|
||||
);
|
||||
) ? 'new' : 'overwrite';
|
||||
const details = {
|
||||
focus: false,
|
||||
history,
|
||||
historyMode,
|
||||
params: this._createSearchParams(type, query, false),
|
||||
state: {
|
||||
sentence,
|
||||
@ -665,7 +672,7 @@ class Display extends EventDispatcher {
|
||||
if (this._contentType === type) { return; }
|
||||
const details = {
|
||||
focus: false,
|
||||
history: false,
|
||||
historyMode: 'clear',
|
||||
params: {type},
|
||||
state: {},
|
||||
content: {
|
||||
@ -725,7 +732,7 @@ class Display extends EventDispatcher {
|
||||
const dictionaryEntries = await yomichan.api.kanjiFind(query, optionsContext);
|
||||
const details = {
|
||||
focus: false,
|
||||
history: true,
|
||||
historyMode: 'new',
|
||||
params: this._createSearchParams('kanji', query, false),
|
||||
state: {
|
||||
focusEntry: 0,
|
||||
@ -1448,7 +1455,7 @@ class Display extends EventDispatcher {
|
||||
const documentTitle = document.title;
|
||||
const details = {
|
||||
focus: false,
|
||||
history: true,
|
||||
historyMode: 'new',
|
||||
params: {
|
||||
type,
|
||||
query,
|
||||
|
@ -185,12 +185,12 @@ class SearchDisplayController {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
this._display.blurElement(e.currentTarget);
|
||||
this._search(true, true, true, null);
|
||||
this._search(true, 'new', true, null);
|
||||
}
|
||||
|
||||
_onSearch(e) {
|
||||
e.preventDefault();
|
||||
this._search(true, true, true, null);
|
||||
this._search(true, 'new', true, null);
|
||||
}
|
||||
|
||||
_onCopy() {
|
||||
@ -205,7 +205,7 @@ class SearchDisplayController {
|
||||
}
|
||||
this._queryInput.value = text;
|
||||
this._updateSearchHeight(true);
|
||||
this._search(animate, false, autoSearchContent, ['clipboard']);
|
||||
this._search(animate, 'clear', autoSearchContent, ['clipboard']);
|
||||
}
|
||||
|
||||
_onWanakanaEnableChange(e) {
|
||||
@ -362,7 +362,7 @@ class SearchDisplayController {
|
||||
});
|
||||
}
|
||||
|
||||
_search(animate, history, lookup, flags) {
|
||||
_search(animate, historyMode, lookup, flags) {
|
||||
const query = this._queryInput.value;
|
||||
const depth = this._display.depth;
|
||||
const url = window.location.href;
|
||||
@ -373,7 +373,7 @@ class SearchDisplayController {
|
||||
}
|
||||
const details = {
|
||||
focus: false,
|
||||
history,
|
||||
historyMode,
|
||||
params: {
|
||||
query
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user