diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-03 21:07:11 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-03 21:10:17 +0900 |
commit | 4b5616b5244f14a8e6b1edf59e944edb7d8ae2d4 (patch) | |
tree | 1acf04feeb4b246240e573744306d227620c7294 /src/components/content-input.js | |
parent | 5ac1f60ece0a112a55f329ed34b455dcc776b22c (diff) |
capture keys on both keypress and keydown
Diffstat (limited to 'src/components/content-input.js')
-rw-r--r-- | src/components/content-input.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/components/content-input.js b/src/components/content-input.js index 53a2f7d..6437128 100644 --- a/src/components/content-input.js +++ b/src/components/content-input.js @@ -2,12 +2,31 @@ import messages from '../content/messages'; export default class ContentInputComponent { constructor(target) { + this.pressed = {}; + target.addEventListener('keypress', this.onKeyPress.bind(this)); target.addEventListener('keydown', this.onKeyDown.bind(this)); target.addEventListener('keyup', this.onKeyUp.bind(this)); } onKeyPress(e) { + this.capture(e); + } + + onKeyDown(e) { + this.capture(e); + } + + onKeyUp(e) { + this.pressed[e.key] = false; + } + + capture(e) { + if (this.pressed[e.key]) { + return; + } + this.pressed[e.key] = true; + if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement) { @@ -22,10 +41,4 @@ export default class ContentInputComponent { ctrl: e.ctrlKey }); } - - onKeyDown() { - } - - onKeyUp() { - } } |