support mutliple modifiers for key bindings

This commit is contained in:
Shin'ya Ueoka 2017-11-05 09:47:30 +09:00
parent 4e94695c75
commit 036ede3379
11 changed files with 75 additions and 75 deletions

View file

@ -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;