Update display key handlers

This commit is contained in:
toasted-nutbread 2019-12-11 21:51:31 -05:00
parent 7837e9f0e3
commit a9c4ce724c

View File

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