summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mousetrap.js8
-rw-r--r--tests/test.mousetrap.js13
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() {