diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-16 21:48:41 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-16 21:48:41 +0900 |
commit | 33a97a0e8c18c099b23cd50a832242985837edca (patch) | |
tree | 73a15a1a39b41e0c42ea79a2d521d63865f83f06 /src/content/components/common/keymapper.js | |
parent | 7ced514f83a69f557c19c1eb24ad792b3f2ace89 (diff) | |
parent | cf3a1eaf16d7dd5c71de57901415fb147793aa56 (diff) |
Merge pull request #61 from ueokande/multi-frame-following
Multi frame following
Diffstat (limited to 'src/content/components/common/keymapper.js')
-rw-r--r-- | src/content/components/common/keymapper.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js new file mode 100644 index 0000000..2a57b28 --- /dev/null +++ b/src/content/components/common/keymapper.js @@ -0,0 +1,34 @@ +import * as inputActions from 'content/actions/input'; +import * as operationActions from 'content/actions/operation'; + +export default class KeymapperComponent { + constructor(store) { + this.store = store; + } + + update() { + } + + key(key, ctrl) { + this.store.dispatch(inputActions.keyPress(key, ctrl)); + + let input = this.store.getState().input; + let matched = Object.keys(input.keymaps).filter((keyStr) => { + return keyStr.startsWith(input.keys); + }); + if (matched.length === 0) { + this.store.dispatch(inputActions.clearKeys()); + return false; + } else if (matched.length > 1 || + matched.length === 1 && input.keys !== matched[0]) { + return true; + } + let operation = input.keymaps[matched]; + this.store.dispatch(operationActions.exec(operation)); + this.store.dispatch(inputActions.clearKeys()); + return true; + } + + onMessage() { + } +} |