Commit fcf15d07 authored by Robert Knight's avatar Robert Knight

Disallow multiple modifier keys

Trigger an error for incorrect use of `matchShortcut` by throwing an
error if multiple non-modifier keys are specified.
parent e786d704
...@@ -30,8 +30,10 @@ export function matchShortcut(event, shortcut) { ...@@ -30,8 +30,10 @@ export function matchShortcut(event, shortcut) {
const modifierFlag = modifiers[part]; const modifierFlag = modifiers[part];
if (modifierFlag) { if (modifierFlag) {
requiredModifiers |= modifierFlag; requiredModifiers |= modifierFlag;
} else { } else if (requiredKey === null) {
requiredKey = part; requiredKey = part;
} else {
throw new Error('Multiple non-modifier keys specified');
} }
} }
......
...@@ -59,6 +59,12 @@ describe('shared/shortcut', () => { ...@@ -59,6 +59,12 @@ describe('shared/shortcut', () => {
}); });
}); });
}); });
it('should throw an error if multiple non-modifier keys are specified', () => {
assert.throws(() => {
matchShortcut(createEvent('a'), 'a+b');
}, 'Multiple non-modifier keys specified');
});
}); });
describe('installShortcut', () => { describe('installShortcut', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment