diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-21 21:17:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-21 21:17:27 +0900 |
commit | 7639e99b755e372712dca36e077a85d9a025cd9f (patch) | |
tree | 177a523e5996e302d647853cf4b11767e669de3c /src/content/components/common/input.js | |
parent | 941073404b534d7f79e90f29b514a5f06fb8080d (diff) | |
parent | 6ad143d294df0a0cc2dfb775ecab9f8b12ee7be5 (diff) |
Merge pull request #86 from ueokande/10-disable-temporary
Disable add-on temporary
Diffstat (limited to 'src/content/components/common/input.js')
-rw-r--r-- | src/content/components/common/input.js | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js index df09894..f285b0c 100644 --- a/src/content/components/common/input.js +++ b/src/content/components/common/input.js @@ -1,3 +1,21 @@ +const modifierdKeyName = (name) => { + if (name.length === 1) { + return name.toUpperCase(); + } else if (name === 'Escape') { + return 'Esc'; + } + return name; +}; + +const mapKey = (e) => { + if (e.ctrlKey) { + return '<C-' + modifierdKeyName(e.key) + '>'; + } else if (e.shiftKey && e.key.length !== 1) { + return '<S-' + modifierdKeyName(e.key) + '>'; + } + return e.key; +}; + export default class InputComponent { constructor(target) { this.pressed = {}; @@ -47,17 +65,16 @@ export default class InputComponent { return; } - let stop = false; + let key = mapKey(e); + for (let listener of this.onKeyListeners) { - stop = stop || listener(e.key, e.ctrlKey); + let stop = listener(key); if (stop) { + e.preventDefault(); + e.stopPropagation(); break; } } - if (stop) { - e.preventDefault(); - e.stopPropagation(); - } } fromInput(e) { |