Add hotkeys to change dictionary (#1243)

* Add nextEntryDifferentDictionary and previousEntryDifferentDictionary hotkeys

* Update settings
This commit is contained in:
toasted-nutbread 2021-01-15 21:11:09 -05:00 committed by GitHub
parent 0a1664ba29
commit 1c5e53a7ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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>

View File

@ -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);
}