aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-15 21:11:09 -0500
committerGitHub <noreply@github.com>2021-01-15 21:11:09 -0500
commit1c5e53a7acec1b58bb2da370d47075a4a0b36ca9 (patch)
treefd7ebcebf85a95c74d942ec0947650dfb4b6d066 /ext/mixed
parent0a1664ba296796c347a1690ff5eea71363961806 (diff)
Add hotkeys to change dictionary (#1243)
* Add nextEntryDifferentDictionary and previousEntryDifferentDictionary hotkeys * Update settings
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/display.js30
1 files changed, 29 insertions, 1 deletions
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);
}