Handle shift + letter combos

pull/21833/head
Clemens Zeidler 2021-02-28 20:12:36 +13:00
parent 54c38844d2
commit f29a8ef0f7
1 changed files with 11 additions and 2 deletions

View File

@ -264,9 +264,18 @@ const autocompleteBindings = (): KeyBinding[] => {
* Note, this method is only exported for testing. * Note, this method is only exported for testing.
*/ */
export function isKeyComboMatch(ev: KeyboardEvent | React.KeyboardEvent, combo: KeyCombo, onMac: boolean): boolean { export function isKeyComboMatch(ev: KeyboardEvent | React.KeyboardEvent, combo: KeyCombo, onMac: boolean): boolean {
if (combo.key !== undefined && ev.key !== combo.key) { if (combo.key !== undefined) {
// When shift is pressed, letters are returned as upper case chars. In this case do a lower case comparison.
// This works for letter combos such as shift + U as well for none letter combos such as shift + Escape.
// If shift is not pressed, the toLowerCase conversion can be avoided.
if (ev.shiftKey) {
if (ev.key.toLowerCase() !== combo.key.toLowerCase()) {
return false; return false;
} }
} else if (ev.key !== combo.key) {
return false;
}
}
const comboCtrl = combo.ctrlKey ?? false; const comboCtrl = combo.ctrlKey ?? false;
const comboAlt = combo.altKey ?? false; const comboAlt = combo.altKey ?? false;