Permalink
Browse files

Make sure mousetrap works with numpad 0

Thanks @jhonatandarosa and @tshinnic for figuring this one out!

Closes #258
  • Loading branch information...
ccampbell committed May 29, 2016
1 parent 3e58a70 commit 35c73fddf78380f69e21493674754a2663a36ea9
Showing with 20 additions and 1 deletion.
  1. +7 −1 mousetrap.js
  2. +13 −0 tests/test.mousetrap.js
View
@@ -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();
}
/**
View
@@ -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() {

0 comments on commit 35c73fd

Please sign in to comment.