diff options
author | Craig Campbell <iamcraigcampbell@gmail.com> | 2016-05-29 09:56:41 -0400 |
---|---|---|
committer | Craig Campbell <iamcraigcampbell@gmail.com> | 2016-05-29 09:57:39 -0400 |
commit | 35c73fddf78380f69e21493674754a2663a36ea9 (patch) | |
tree | 5f0fd0a2d9e285b3ae708b39d4e7723252ba0f36 | |
parent | 3e58a70435975dd13a91dee132fcb6a8eaeb943f (diff) | |
download | mousetrap-origin/master.zip mousetrap-origin/master.tar.gz mousetrap-origin/master.tar.bz2 |
Make sure mousetrap works with numpad 0HEADorigin/masterorigin/HEADmaster
Thanks @jhonatandarosa and @tshinnic for figuring this one out!
Closes #258
-rw-r--r-- | mousetrap.js | 8 | ||||
-rw-r--r-- | tests/test.mousetrap.js | 13 |
2 files changed, 20 insertions, 1 deletions
diff --git a/mousetrap.js b/mousetrap.js index 74e7e72..5a56da3 100644 --- a/mousetrap.js +++ b/mousetrap.js @@ -156,7 +156,13 @@ * loop through to map numbers on the numeric keypad */ for (i = 0; i <= 9; ++i) { - _MAP[i + 96] = i; + + // This needs to use a string cause otherwise since 0 is falsey + // mousetrap will never fire for numpad 0 pressed as part of a keydown + // event. + // + // @see https://github.com/ccampbell/mousetrap/pull/258 + _MAP[i + 96] = i.toString(); } /** diff --git a/tests/test.mousetrap.js b/tests/test.mousetrap.js index da5829b..98310da 100644 --- a/tests/test.mousetrap.js +++ b/tests/test.mousetrap.js @@ -269,6 +269,19 @@ describe('Mousetrap.bind', function() { KeyEvent.simulate('O'.charCodeAt(0), 79, ['meta', 'shift']); expect(spy.callCount).to.equal(1, 'command+o callback should fire'); }); + + it('should fire callback when ctrl+numpad 0 is pressed', function() { + var spy = sinon.spy(); + + Mousetrap.bind('ctrl+0', spy); + + // numpad 0 keycode + KeyEvent.simulate(96, 96, ['ctrl']); + + expect(spy.callCount).to.equal(1, 'callback should fire once'); + expect(spy.args[0][0]).to.be.an.instanceOf(Event, 'first argument should be Event'); + expect(spy.args[0][1]).to.equal('ctrl+0', 'second argument should be key combo'); + }); }); describe('sequences', function() { |