fix for symbol keys

jh-changes
Shin'ya Ueoka 7 years ago
parent 036ede3379
commit ccf3c7b421
  1. 10
      src/shared/utils/keys.js
  2. 12
      test/shared/utils/keys.test.js

@ -8,9 +8,17 @@ const modifierdKeyName = (name) => {
};
const fromKeyboardEvent = (e) => {
let key = modifierdKeyName(e.key);
let shift = e.shiftKey;
if (key.length === 1 && key.toUpperCase() === key.toLowerCase()) {
// make shift false for symbols to enable key bindings by symbold keys.
// But this limits key bindings by symbol keys with Shift (such as Shift+$>.
shift = false;
}
return {
key: modifierdKeyName(e.key),
shiftKey: e.shiftKey,
shiftKey: shift,
ctrlKey: e.ctrlKey,
altKey: e.altKey,
metaKey: e.metaKey,

@ -24,6 +24,18 @@ describe("keys util", () => {
expect(k.altKey).to.be.false;
expect(k.metaKey).to.be.true;
});
it('returns from keyboard input Ctrl+$', () => {
// $ required shift pressing on most keyboards
let k = keys.fromKeyboardEvent({
key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false
});
expect(k.key).to.equal('$');
expect(k.shiftKey).to.be.false;
expect(k.ctrlKey).to.be.true;
expect(k.altKey).to.be.false;
expect(k.metaKey).to.be.false;
});
});
describe('fromMapKey', () => {