keyboard shortcuts
This commit is contained in:
parent
f5a8383d2a
commit
2580dd8e7f
@ -211,7 +211,13 @@ class Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
const requireAlt = ['e', 'k', 'p'];
|
const noteTryAdd = mode => {
|
||||||
|
const button = Display.adderButtonFind(this.index, mode);
|
||||||
|
if (button.length !== 0 && !button.hasClass('disabled')) {
|
||||||
|
this.noteAdd(this.definitions[this.index], mode);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
27: /* escape */ () => {
|
27: /* escape */ () => {
|
||||||
this.clearSearch();
|
this.clearSearch();
|
||||||
@ -242,20 +248,26 @@ class Display {
|
|||||||
},
|
},
|
||||||
|
|
||||||
69: /* e */ () => {
|
69: /* e */ () => {
|
||||||
this.noteAdd(this.definitions[this.index], 'term-kanji');
|
noteTryAdd('term-kanji');
|
||||||
},
|
},
|
||||||
|
|
||||||
75: /* k */ () => {
|
75: /* k */ () => {
|
||||||
this.noteAdd(this.definitions[this.index], 'term-kana');
|
noteTryAdd('kanji');
|
||||||
|
},
|
||||||
|
|
||||||
|
82: /* r */ () => {
|
||||||
|
noteTryAdd('term-kana');
|
||||||
},
|
},
|
||||||
|
|
||||||
80: /* p */ () => {
|
80: /* p */ () => {
|
||||||
|
if (Display.adderButtonFind(this.index, 'kanji').length === 0) {
|
||||||
this.audioPlay(this.definitions[this.index]);
|
this.audioPlay(this.definitions[this.index]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handler = handlers[e.keyCode];
|
const handler = handlers[e.keyCode];
|
||||||
if (handler && (e.altKey || !requireAlt.includes(e.keyCode))) {
|
if (handler && (e.altKey || !['e', 'k', 'p'].includes(e.keyCode))) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handler();
|
handler();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user