summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-08-30 21:55:08 -0400
committerGitHub <noreply@github.com>2021-08-30 21:55:08 -0400
commit3e7f3af63c01e39577bdc548d0dc81e83020df78 (patch)
tree6d53659ed2ebd9a133e4aaa2f0056701983c4cd6
parentf565cc5a474c69a5096eaf19cb7c374fe01cb851 (diff)
Fix history replacement issue (#1917)
* Remove unused "history" field of event details * Change setContent history parameter to historyMode
-rw-r--r--ext/js/app/frontend.js2
-rw-r--r--ext/js/display/display-history.js2
-rw-r--r--ext/js/display/display.js35
-rw-r--r--ext/js/display/search-display-controller.js10
4 files changed, 28 insertions, 21 deletions
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js
index 1c6def06..ef53cecb 100644
--- a/ext/js/app/frontend.js
+++ b/ext/js/app/frontend.js
@@ -515,7 +515,7 @@ class Frontend {
const {url} = optionsContext;
const details = {
focus,
- history: false,
+ historyMode: 'clear',
params: {
type,
query,
diff --git a/ext/js/display/display-history.js b/ext/js/display/display-history.js
index a6335521..449bec47 100644
--- a/ext/js/display/display-history.js
+++ b/ext/js/display/display-history.js
@@ -112,7 +112,7 @@ class DisplayHistory extends EventDispatcher {
}
_triggerStateChanged(synthetic) {
- this.trigger('stateChanged', {history: this, synthetic});
+ this.trigger('stateChanged', {synthetic});
}
_updateHistoryFromCurrent(replace) {
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index f3d46054..edd9a866 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -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 {
- this._history.clear();
- this._history.replaceState(state, content, url);
+ 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,
diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js
index 6bdef2c8..81124bbb 100644
--- a/ext/js/display/search-display-controller.js
+++ b/ext/js/display/search-display-controller.js
@@ -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
},