aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/keymapper.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-12 18:25:14 +0900
committerGitHub <noreply@github.com>2017-11-12 18:25:14 +0900
commitc7b05482f33cc778e1966faa9354ea46b490a115 (patch)
treeb73bc6e5a6468d8c5a1118dcfb61f9d00b1aa5cf /src/content/components/common/keymapper.js
parent3af2e3154ed6b56400d02fc3d726bfc7186f372a (diff)
parentccf3c7b421e804172827dd34a995290afc85af10 (diff)
Merge pull request #132 from ueokande/meta-keys
Meta keys
Diffstat (limited to 'src/content/components/common/keymapper.js')
-rw-r--r--src/content/components/common/keymapper.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js
index 1da3c0d..0abbc91 100644
--- a/src/content/components/common/keymapper.js
+++ b/src/content/components/common/keymapper.js
@@ -1,6 +1,19 @@
import * as inputActions from 'content/actions/input';
import * as operationActions from 'content/actions/operation';
import operations from 'shared/operations';
+import * as keyUtils from 'shared/utils/keys';
+
+const mapStartsWith = (mapping, keys) => {
+ if (mapping.length < keys.length) {
+ return false;
+ }
+ for (let i = 0; i < keys.length; ++i) {
+ if (!keyUtils.equals(mapping[i], keys[i])) {
+ return false;
+ }
+ }
+ return true;
+};
export default class KeymapperComponent {
constructor(store) {
@@ -14,14 +27,14 @@ export default class KeymapperComponent {
let input = state.input;
let keymaps = state.setting.keymaps;
- let matched = Object.keys(keymaps).filter((keyStr) => {
- return keyStr.startsWith(input.keys);
+ let matched = Array.from(keymaps.keys()).filter((mapping) => {
+ return mapStartsWith(mapping, input.keys);
});
if (!state.addon.enabled) {
// available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if
// the addon disabled
matched = matched.filter((keys) => {
- let type = keymaps[keys].type;
+ let type = keymaps.get(keys).type;
return type === operations.ADDON_ENABLE ||
type === operations.ADDON_TOGGLE_ENABLED;
});
@@ -30,10 +43,10 @@ export default class KeymapperComponent {
this.store.dispatch(inputActions.clearKeys());
return false;
} else if (matched.length > 1 ||
- matched.length === 1 && input.keys !== matched[0]) {
+ matched.length === 1 && input.keys.length < matched[0].length) {
return true;
}
- let operation = keymaps[matched];
+ let operation = keymaps.get(matched[0]);
this.store.dispatch(operationActions.exec(operation));
this.store.dispatch(inputActions.clearKeys());
return true;