summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/settings2.html2
-rw-r--r--ext/mixed/js/display.js30
2 files changed, 31 insertions, 1 deletions
diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html
index 0beef025..08dc92d5 100644
--- a/ext/bg/settings2.html
+++ b/ext/bg/settings2.html
@@ -2879,6 +2879,8 @@
<option value="previousEntry3">Go to previous entry (x3)</option>
<option value="lastEntry">Go to last entry</option>
<option value="firstEntry">Go to first entry</option>
+ <option value="nextEntryDifferentDictionary">Go to next dictionary</option>
+ <option value="previousEntryDifferentDictionary">Go to previous dictionary</option>
<option value="historyBackward">Navigate backward in history</option>
<option value="historyForward">Navigate forward in history</option>
<option value="addNoteKanji">Add kanji note</option>
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 8558d849..67db9097 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -130,7 +130,9 @@ class Display extends EventDispatcher {
['addNoteTermKana', () => { this._tryAddAnkiNoteForSelectedDefinition('term-kana'); }],
['viewNote', () => { this._tryViewAnkiNoteForSelectedDefinition(); }],
['playAudio', () => { this._playAudioCurrent(); }],
- ['copyHostSelection', () => this._copyHostSelection()]
+ ['copyHostSelection', () => this._copyHostSelection()],
+ ['nextEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(1, true); }],
+ ['previousEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(-1, true); }]
]);
this.registerMessageHandlers([
['setMode', {async: false, handler: this._onMessageSetMode.bind(this)}]
@@ -1144,6 +1146,32 @@ class Display extends EventDispatcher {
}
}
+ _focusEntryWithDifferentDictionary(offset, smooth) {
+ const offsetSign = Math.sign(offset);
+ if (offsetSign === 0) { return false; }
+
+ let index = this._index;
+ const definitionCount = this._definitions.length;
+ if (index < 0 || index >= definitionCount) { return false; }
+
+ const {dictionary} = this._definitions[index];
+ for (let indexNext = index + offsetSign; indexNext >= 0 && indexNext < definitionCount; indexNext += offsetSign) {
+ const {dictionaryNames} = this._definitions[indexNext];
+ if (dictionaryNames.length > 1 || !dictionaryNames.includes(dictionary)) {
+ offset -= offsetSign;
+ if (Math.sign(offsetSign) !== offset) {
+ index = indexNext;
+ break;
+ }
+ }
+ }
+
+ if (index === this._index) { return false; }
+
+ this._focusEntry(index, smooth);
+ return true;
+ }
+
_sourceTermView() {
this._relativeTermView(false);
}