From 2580dd8e7fc21bc5c39521f777a53c2aa790cfe1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 17:53:25 -0700 Subject: keyboard shortcuts --- ext/mixed/js/display.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index dca32e78..639c2673 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -211,7 +211,13 @@ class Display { } 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 = { 27: /* escape */ () => { this.clearSearch(); @@ -242,20 +248,26 @@ class Display { }, 69: /* e */ () => { - this.noteAdd(this.definitions[this.index], 'term-kanji'); + noteTryAdd('term-kanji'); }, 75: /* k */ () => { - this.noteAdd(this.definitions[this.index], 'term-kana'); + noteTryAdd('kanji'); + }, + + 82: /* r */ () => { + noteTryAdd('term-kana'); }, 80: /* p */ () => { - this.audioPlay(this.definitions[this.index]); + if (Display.adderButtonFind(this.index, 'kanji').length === 0) { + this.audioPlay(this.definitions[this.index]); + } } }; 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(); handler(); } -- cgit v1.2.3