diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-21 11:06:58 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-21 12:47:44 +0900 |
commit | 214a5103f3e2914028206a13ba115c69a7ee07f1 (patch) | |
tree | f396f94064ae1626ae134e1932316fa11641c7c0 /src/content/components | |
parent | c2a663a64d23816821d333c0d1c7c7c968f494b0 (diff) |
emit mapped keys from input-component
Diffstat (limited to 'src/content/components')
-rw-r--r-- | src/content/components/common/index.js | 4 | ||||
-rw-r--r-- | src/content/components/common/input.js | 11 | ||||
-rw-r--r-- | src/content/components/common/keymapper.js | 4 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 98a2337..db0ac43 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -10,8 +10,8 @@ export default class Common { const input = new InputComponent(win.document.body, store); const keymapper = new KeymapperComponent(store); - input.onKey((key, ctrl) => follow.key(key, ctrl)); - input.onKey((key, ctrl) => keymapper.key(key, ctrl)); + input.onKey(key => follow.key(key)); + input.onKey(key => keymapper.key(key)); this.store = store; this.children = [ diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js index 2de0d7d..9af9fbe 100644 --- a/src/content/components/common/input.js +++ b/src/content/components/common/input.js @@ -1,3 +1,10 @@ +const mapKey = (e) => { + if (e.ctrlKey) { + return '<C-' + e.key.toUpperCase() + '>'; + } + return e.key; +}; + export default class InputComponent { constructor(target) { this.pressed = {}; @@ -47,8 +54,10 @@ export default class InputComponent { return; } + let key = mapKey(e); + for (let listener of this.onKeyListeners) { - let stop = listener(e.key, e.ctrlKey); + let stop = listener(key); if (stop) { e.preventDefault(); e.stopPropagation(); diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index 655c3f2..8c0ddb1 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -9,8 +9,8 @@ export default class KeymapperComponent { update() { } - key(key, ctrl) { - this.store.dispatch(inputActions.keyPress(key, ctrl)); + key(key) { + this.store.dispatch(inputActions.keyPress(key)); let input = this.store.getState().input; let matched = Object.keys(input.keymaps).filter((keyStr) => { |