vendor/assets/javascripts/mousetrap.js in mousetrap-rails-0.0.10 vs vendor/assets/javascripts/mousetrap.js in mousetrap-rails-0.0.11
- old
+ new
@@ -15,11 +15,11 @@
* limitations under the License.
*
* Mousetrap is a simple keyboard shortcut library for Javascript with
* no external dependencies
*
- * @version 1.4.1
+ * @version 1.4.4
* @url craig.is/killing/mice
*/
(function() {
/**
@@ -173,10 +173,17 @@
* @type {boolean|string}
*/
_ignoreNextKeyup = false,
/**
+ * temporary state where we will ignore the next keypress
+ *
+ * @type {boolean}
+ */
+ _ignoreNextKeypress = false,
+
+ /**
* are we currently inside of a sequence?
* type of action ("keyup" or "keydown" or "keypress") or false
*
* @type {boolean|string}
*/
@@ -237,10 +244,16 @@
// trigger the event. shift+a will though.
if (!e.shiftKey) {
character = character.toLowerCase();
}
+ // String.fromCharCode(32) for spacebar returns " " for the
+ // character name, make sure it matches the mousetrap name
+ if (character == ' ') {
+ return 'space';
+ }
+
return character;
}
// for non keypress events the special maps are needed
if (_MAP[e.which]) {
@@ -494,13 +507,26 @@
// cause the sequence to reset
//
// modifier keys are ignored because you can have a sequence
// that contains modifiers such as "enter ctrl+space" and in most
// cases the modifier key will be pressed before the next key
- if (e.type == _nextExpectedAction && !_isModifier(character)) {
+ //
+ // also if you have a sequence such as "ctrl+b a" then pressing the
+ // "b" key will trigger a "keypress" and a "keydown"
+ //
+ // the "keydown" is expected when there is a modifier, but the
+ // "keypress" ends up matching the _nextExpectedAction since it occurs
+ // after and that causes the sequence to reset
+ //
+ // we ignore keypresses in a sequence that directly follow a keydown
+ // for the same character
+ var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress;
+ if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
_resetSequences(doNotReset);
}
+
+ _ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown';
}
/**
* handles a keydown event
*
@@ -520,10 +546,11 @@
// no character found then stop
if (!character) {
return;
}
- if (e.type == 'keyup' && _ignoreNextKeyup == character) {
+ // need to use === for the character check because the character can be 0
+ if (e.type == 'keyup' && _ignoreNextKeyup === character) {
_ignoreNextKeyup = false;
return;
}
Mousetrap.handleKey(character, _eventModifiers(e), e);