summaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/display.js50
1 files changed, 22 insertions, 28 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index e361a3a1..45019039 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -132,23 +132,6 @@ class Display extends EventDispatcher {
['playAudio', () => { this._playAudioCurrent(); }],
['copyHostSelection', () => this._copyHostSelection()]
]);
- this.registerHotkeys([
- {key: 'Escape', modifiers: [], action: 'close'},
- {key: 'PageUp', modifiers: ['alt'], action: 'previousEntry3'},
- {key: 'PageDown', modifiers: ['alt'], action: 'nextEntry3'},
- {key: 'End', modifiers: ['alt'], action: 'lastEntry'},
- {key: 'Home', modifiers: ['alt'], action: 'firstEntry'},
- {key: 'ArrowUp', modifiers: ['alt'], action: 'previousEntry'},
- {key: 'ArrowDown', modifiers: ['alt'], action: 'nextEntry'},
- {key: 'KeyB', modifiers: ['alt'], action: 'historyBackward'},
- {key: 'KeyF', modifiers: ['alt'], action: 'historyForward'},
- {key: 'KeyK', modifiers: ['alt'], action: 'addNoteKanji'},
- {key: 'KeyE', modifiers: ['alt'], action: 'addNoteTermKanji'},
- {key: 'KeyR', modifiers: ['alt'], action: 'addNoteTermKana'},
- {key: 'KeyP', modifiers: ['alt'], action: 'playAudio'},
- {key: 'KeyV', modifiers: ['alt'], action: 'viewNote'},
- {key: 'KeyC', modifiers: ['ctrl'], action: 'copyHostSelection'}
- ]);
this.registerMessageHandlers([
['setMode', {async: false, handler: this._onMessageSetMode.bind(this)}]
]);
@@ -313,6 +296,7 @@ class Display extends EventDispatcher {
this._options = options;
this._ankiFieldTemplates = templates;
+ this._updateHotkeys(options);
this._updateDocumentOptions(options);
this._updateTheme(options.general.popupTheme);
this.setCustomCss(options.general.customPopupCss);
@@ -401,17 +385,6 @@ class Display extends EventDispatcher {
}
}
- registerHotkeys(hotkeys) {
- for (const {key, modifiers, action} of hotkeys) {
- let handlers = this._hotkeys.get(key);
- if (typeof handlers === 'undefined') {
- handlers = [];
- this._hotkeys.set(key, handlers);
- }
- handlers.push({modifiers: new Set(modifiers), action});
- }
- }
-
registerMessageHandlers(handlers) {
for (const [name, handlerInfo] of handlers) {
this._messageHandlers.set(name, handlerInfo);
@@ -1902,4 +1875,25 @@ class Display extends EventDispatcher {
height = Math.max(Math.max(0, handleSize.height), height);
await this._invokeOwner('setFrameSize', {width, height});
}
+
+ _registerHotkey(key, modifiers, action) {
+ if (!this._actions.has(action)) { return false; }
+
+ let handlers = this._hotkeys.get(key);
+ if (typeof handlers === 'undefined') {
+ handlers = [];
+ this._hotkeys.set(key, handlers);
+ }
+ handlers.push({modifiers: new Set(modifiers), action});
+ return true;
+ }
+
+ _updateHotkeys(options) {
+ this._hotkeys.clear();
+
+ for (const {action, key, modifiers, scopes, enabled} of options.inputs.hotkeys) {
+ if (!enabled || !scopes.includes(this._pageType)) { continue; }
+ this._registerHotkey(key, modifiers, action);
+ }
+ }
}