diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-11-12 18:21:28 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-11-12 18:21:28 +0900 |
commit | ccf3c7b421e804172827dd34a995290afc85af10 (patch) | |
tree | a42c2d121b2fa252340befe8bad2063121812f59 | |
parent | 036ede3379285cbe678d79aad3b9442dca8b31e6 (diff) |
fix for symbol keys
-rw-r--r-- | src/shared/utils/keys.js | 10 | ||||
-rw-r--r-- | test/shared/utils/keys.test.js | 12 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/shared/utils/keys.js b/src/shared/utils/keys.js index dfdb954..fba8ce3 100644 --- a/src/shared/utils/keys.js +++ b/src/shared/utils/keys.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, diff --git a/test/shared/utils/keys.test.js b/test/shared/utils/keys.test.js index 77e2b12..5ca8b54 100644 --- a/test/shared/utils/keys.test.js +++ b/test/shared/utils/keys.test.js @@ -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', () => { |