summaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-11-28 15:20:18 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-28 15:20:18 +0200
commitbeea89a421736ec157e196ffca6b3720a811635d (patch)
tree9c46b264f942a1aa2a7f3356e7997547e5bdae45 /ext/mixed
parent4e7d08ff2c184a361622a6efaf00e21af51428a9 (diff)
store popped context history in Display
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/display.js54
1 files changed, 51 insertions, 3 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index ed3d9adc..bd4b13d1 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -37,6 +37,8 @@ class Display {
this.eventListenersActive = false;
this.clickScanPrevent = false;
+ this.poppedContextHistory = [];
+
this.windowScroll = new WindowScroll();
this.setInteractive(true);
@@ -55,10 +57,16 @@ class Display {
this.sourceTermView();
}
+ onHistoryTermView(e) {
+ e.preventDefault();
+ this.poppedTermView();
+ }
+
async onKanjiLookup(e) {
try {
e.preventDefault();
if (!this.context) { return; }
+ this.poppedContextHistory = [];
const link = e.target;
const context = {
@@ -72,6 +80,7 @@ class Display {
})
}
},
+ type: 'kanji',
sentence: this.context.sentence,
url: this.context.url
};
@@ -104,6 +113,7 @@ class Display {
async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) {
try {
if (!this.context) { return; }
+ this.poppedContextHistory = [];
const termLookupResults = await this.termLookup(e);
if (!termLookupResults) { return; }
const {textSource, definitions} = termLookupResults;
@@ -122,6 +132,7 @@ class Display {
})
}
},
+ type: 'terms',
disableScroll,
sentence,
url: this.context.url
@@ -207,12 +218,20 @@ class Display {
onWheel(e) {
if (e.altKey) {
- const delta = e.deltaY;
- if (delta !== 0) {
- this.entryScrollIntoView(this.index + (delta > 0 ? 1 : -1), null, true);
+ if (e.deltaY !== 0) {
+ this.entryScrollIntoView(this.index + (e.deltaY > 0 ? 1 : -1), null, true);
e.preventDefault();
}
}
+ if (e.shiftKey) {
+ const delta = e.deltaX || e.deltaY;
+ if (delta > 0) {
+ this.sourceTermView();
+ e.preventDefault();
+ } else if (delta < 0) {
+ this.poppedTermView();
+ }
+ }
}
onRuntimeMessage({action, params}, sender, callback) {
@@ -293,6 +312,7 @@ class Display {
this.addEventListeners('.action-play-audio', 'click', this.onAudioPlay.bind(this));
this.addEventListeners('.kanji-link', 'click', this.onKanjiLookup.bind(this));
this.addEventListeners('.source-term', 'click', this.onSourceTermView.bind(this));
+ this.addEventListeners('.history-term', 'click', this.onHistoryTermView.bind(this));
if (this.options.scanning.enablePopupSearch) {
this.addEventListeners('.glossary-item', 'mouseup', this.onGlossaryMouseUp.bind(this));
this.addEventListeners('.glossary-item', 'mousedown', this.onGlossaryMouseDown.bind(this));
@@ -342,6 +362,7 @@ class Display {
const params = {
definitions,
source: context.source,
+ history: this.poppedContextHistory.length > 0,
addable: options.anki.enable,
grouped: options.general.resultOutputMode === 'group',
merged: options.general.resultOutputMode === 'merge',
@@ -396,6 +417,7 @@ class Display {
const params = {
definitions,
source: context.source,
+ history: this.poppedContextHistory.length > 0,
addable: options.anki.enable,
debug: options.general.debugInfo
};
@@ -506,10 +528,28 @@ class Display {
sourceTermView() {
if (!this.context || !this.context.source) { return; }
+ this.poppedContextHistory.push({
+ type: this.context.type,
+ details: {
+ definitions: this.definitions,
+ context: Object.assign({}, this.context, {
+ index: this.index,
+ scroll: this.windowScroll.y
+ })
+ }
+ });
const {type, details} = this.context.source;
this.setContent(type, details);
}
+ poppedTermView() {
+ if (this.poppedContextHistory.length === 0) { return; }
+ this.context.index = this.index;
+ this.context.scroll = this.windowScroll.y;
+ const {type, details} = this.poppedContextHistory.pop();
+ this.setContent(type, details);
+ }
+
noteTryAdd(mode) {
const button = this.adderButtonFind(this.index, mode);
if (button !== null && !button.classList.contains('disabled')) {
@@ -783,6 +823,14 @@ Display.onKeyDownHandlers = {
return false;
},
+ 'F': (self, e) => {
+ if (e.altKey) {
+ self.poppedTermView();
+ return true;
+ }
+ return false;
+ },
+
'E': (self, e) => {
if (e.altKey) {
self.noteTryAdd('term-kanji');