diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-11 21:51:31 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-13 23:11:56 -0500 |
commit | a9c4ce724caf4824b8bb6f6fffe3db4c9dbb7bf6 (patch) | |
tree | 310786d94b5f8d890d5229e8e3dd44faa4a10e4b | |
parent | 7837e9f0e3e3671bcc939506c795bce8b3065514 (diff) |
Update display key handlers
-rw-r--r-- | ext/mixed/js/display.js | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 9d3dc51b..ab0674a9 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -193,9 +193,8 @@ class Display { onKeyDown(e) { const key = Display.getKeyFromEvent(e); - const handlers = Display.onKeyDownHandlers; - if (hasOwn(handlers, key)) { - const handler = handlers[key]; + const handler = Display._onKeyDownHandlers.get(key); + if (typeof handler === 'function') { if (handler(this, e)) { e.preventDefault(); return true; @@ -766,101 +765,101 @@ class Display { } } -Display.onKeyDownHandlers = { - 'Escape': (self) => { +Display._onKeyDownHandlers = new Map([ + ['Escape', (self) => { self.onSearchClear(); return true; - }, + }], - 'PageUp': (self, e) => { + ['PageUp', (self, e) => { if (e.altKey) { self.entryScrollIntoView(self.index - 3, null, true); return true; } return false; - }, + }], - 'PageDown': (self, e) => { + ['PageDown', (self, e) => { if (e.altKey) { self.entryScrollIntoView(self.index + 3, null, true); return true; } return false; - }, + }], - 'End': (self, e) => { + ['End', (self, e) => { if (e.altKey) { self.entryScrollIntoView(self.definitions.length - 1, null, true); return true; } return false; - }, + }], - 'Home': (self, e) => { + ['Home', (self, e) => { if (e.altKey) { self.entryScrollIntoView(0, null, true); return true; } return false; - }, + }], - 'ArrowUp': (self, e) => { + ['ArrowUp', (self, e) => { if (e.altKey) { self.entryScrollIntoView(self.index - 1, null, true); return true; } return false; - }, + }], - 'ArrowDown': (self, e) => { + ['ArrowDown', (self, e) => { if (e.altKey) { self.entryScrollIntoView(self.index + 1, null, true); return true; } return false; - }, + }], - 'B': (self, e) => { + ['B', (self, e) => { if (e.altKey) { self.sourceTermView(); return true; } return false; - }, + }], - 'F': (self, e) => { + ['F', (self, e) => { if (e.altKey) { self.nextTermView(); return true; } return false; - }, + }], - 'E': (self, e) => { + ['E', (self, e) => { if (e.altKey) { self.noteTryAdd('term-kanji'); return true; } return false; - }, + }], - 'K': (self, e) => { + ['K', (self, e) => { if (e.altKey) { self.noteTryAdd('kanji'); return true; } return false; - }, + }], - 'R': (self, e) => { + ['R', (self, e) => { if (e.altKey) { self.noteTryAdd('term-kana'); return true; } return false; - }, + }], - 'P': (self, e) => { + ['P', (self, e) => { if (e.altKey) { const entry = self.getEntry(self.index); if (entry !== null && entry.dataset.type === 'term') { @@ -869,16 +868,16 @@ Display.onKeyDownHandlers = { return true; } return false; - }, + }], - 'V': (self, e) => { + ['V', (self, e) => { if (e.altKey) { self.noteTryView(); return true; } return false; - } -}; + }] +]); Display._runtimeMessageHandlers = new Map([ ['optionsUpdate', (self) => self.updateOptions(null)] |