Skip to content

Commit

Permalink
🐛 Fix #183: Add separate dictionary of keys that cmd hides the keyup …
Browse files Browse the repository at this point in the history
…events for
  • Loading branch information
greena13 committed Jun 8, 2019
1 parent bf262c3 commit a90811b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/const/KeysWithKeyupHiddenByCmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Dictionary of keys that, when pressed down with the cmd key, never trigger a keyup
* event in the browser
*/
const KeysWithKeyupHiddenByCmd = {
Enter: true,
Backspace: true,
ArrowRight: true,
ArrowLeft: true,
ArrowUp: true,
ArrowDown: true,
/**
* Caps lock is a strange case where it not only does not have a key press event,
* but it's keyup event is triggered when caps lock is toggled off
*/
CapsLock: true,
};

for(let i = 1; i < 13; i++) {
KeysWithKeyupHiddenByCmd[`F${i}`] = true;
}

export default KeysWithKeyupHiddenByCmd;
14 changes: 14 additions & 0 deletions src/helpers/resolving-handlers/keyupIsHiddenByCmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import KeysWithKeyupHiddenByCmd from '../../const/KeysWithKeyupHiddenByCmd';
import hasKey from '../../utils/object/hasKey';

/**
* Whether the specified key, when pressed down with the cmd key, never triggers a keyup
* event in the browser
* @param {NormalizedKeyName} keyName Name of the key
* @returns {Boolean} Whether the key has its keyup event hidden by cmd
*/
function keyupIsHiddenByCmd(keyName) {
return keyName.length === 1 || hasKey(KeysWithKeyupHiddenByCmd, keyName);
}

export default keyupIsHiddenByCmd;
2 changes: 1 addition & 1 deletion src/lib/KeyEventBitmapManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class KeyEventBitmapManager {
* @param {KeyEventBitmapIndex=} eventBitmapIndex Index of bit to set to true
* @returns {KeyEventBitmap} New key event bitmap with bit set to true
*/
static newBitmap(eventBitmapIndex ) {
static newBitmap(eventBitmapIndex) {
const bitmap = [ false, false, false ];

if (!isUndefined(eventBitmapIndex)) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/strategies/AbstractKeyEventStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import keyIsCurrentlyTriggeringEvent from '../../helpers/parsing-key-maps/keyIsC
import isMatchPossibleBasedOnNumberOfKeys from '../../helpers/resolving-handlers/isMatchPossibleBasedOnNumberOfKeys';
import copyAttributes from '../../utils/object/copyAttributes';
import hasKey from '../../utils/object/hasKey';
import keyupIsHiddenByCmd from '../../helpers/resolving-handlers/keyupIsHiddenByCmd';

const SEQUENCE_ATTRIBUTES = ['sequence', 'action'];
const KEYMAP_ATTRIBUTES = ['name', 'description', 'group'];
Expand Down Expand Up @@ -769,7 +770,7 @@ class AbstractKeyEventStrategy {
if (eventType === KeyEventBitmapIndex.keypress) {
return !keyHasNativeKeypress || (keyHasNativeKeypress && this._keyIsCurrentlyDown('Meta'));
} else if (eventType === KeyEventBitmapIndex.keyup) {
return (keyHasNativeKeypress && keyIsCurrentlyTriggeringEvent(
return (keyupIsHiddenByCmd(keyName) && keyIsCurrentlyTriggeringEvent(
this._getCurrentKeyState('Meta'),
KeyEventBitmapIndex.keyup)
);
Expand Down

0 comments on commit a90811b

Please sign in to comment.