Skip to content

Commit

Permalink
Changes the keyCombo splitting, allowing it to contain plus signs (+)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoeuclids committed Mar 8, 2024
1 parent 7f73884 commit 785bf37
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions addon/src/utils/keyboard-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,43 @@ export default class KeyboardListener {
keyCombo = keyCombo.join(':'); // allow keyCombo contain semicolon
keyboardListener.type = eventType;

if (keyCombo === '+') {
keyboardListener.keyOrCode = keyCombo;
return keyboardListener;
}
let maybePlus = false;
keyCombo
.split('+')
.reduce((result, part) => {
if (part === '') {
if (maybePlus) {
result.push('+');
}

keyCombo.split('+').forEach((part) => {
if (ALT_REGEX.test(part)) {
keyboardListener.altKey = true;
} else if (CTRL_REGEX.test(part)) {
keyboardListener.ctrlKey = true;
} else if (META_REGEX.test(part)) {
keyboardListener.metaKey = true;
} else if (SHIFT_REGEX.test(part)) {
keyboardListener.shiftKey = true;
} else if (CMD_REGEX.test(part)) {
if (platform.indexOf('Mac') > -1) {
keyboardListener.metaKey = true;
maybePlus = !maybePlus;
} else {
result.push(part);
}

return result;
}, [])
.forEach((part) => {
if (ALT_REGEX.test(part)) {
keyboardListener.altKey = true;
} else if (CTRL_REGEX.test(part)) {
keyboardListener.ctrlKey = true;
} else if (META_REGEX.test(part)) {
keyboardListener.metaKey = true;
} else if (SHIFT_REGEX.test(part)) {
keyboardListener.shiftKey = true;
} else if (CMD_REGEX.test(part)) {
if (platform.indexOf('Mac') > -1) {
keyboardListener.metaKey = true;
} else {
keyboardListener.ctrlKey = true;
}
} else {
keyboardListener.keyOrCode = part;
}
} else {
keyboardListener.keyOrCode = part;
}
});
);

return keyboardListener;
}

Expand Down

0 comments on commit 785bf37

Please sign in to comment.