Skip to content

Commit 986d476

Browse files
Correct space and delete
1 parent 5b10084 commit 986d476

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/core/src/components/hotkeys/hotkeyParser.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,19 @@ export const getKeyCombo = (e: KeyboardEvent): KeyCombo => {
199199
if (MODIFIER_KEYS.has(e.key)) {
200200
// Leave local variable `key` undefined
201201
} else {
202-
// Use event.key to respect keyboard layout, but handle Alt-modified characters specially
203-
// Alt on macOS produces special characters (e.g., Alt+c → ç), so we fall back to code for those cases
204-
if (e.altKey && isAltModifiedCharacter(e.key) && maybeGetKeyFromEventCode(e) !== undefined) {
205-
key = maybeGetKeyFromEventCode(e);
202+
const codeKey = maybeGetKeyFromEventCode(e);
203+
204+
// Special cases where we must use code instead of key
205+
if (e.code === "Space" || e.code === "Delete") {
206+
// Space: event.key is " " but we need "space" to match parseKeyCombo
207+
// Delete: need lowercase code name
208+
key = codeKey;
209+
} else if (e.altKey && isAltModifiedCharacter(e.key) && codeKey !== undefined) {
210+
// Alt on macOS produces special characters (e.g., Alt+c → ç), use code for those cases
211+
key = codeKey;
206212
} else {
207-
key = e.key?.toLowerCase();
213+
// Prefer event.key to respect keyboard layout, fall back to code
214+
key = e.key?.toLowerCase() ?? codeKey;
208215
}
209216
}
210217

@@ -237,8 +244,8 @@ function isAltModifiedCharacter(key: string): boolean {
237244
return false;
238245
}
239246
const code = key.charCodeAt(0);
240-
// Check if it's outside normal ASCII printable range (32-126) or control characters
241-
return code > 126 || code < 32;
247+
// Check if it's outside the normal ASCII printable range (32-127), excluding space and delete (32 & 127)
248+
return code > 126 || code < 33;
242249
}
243250

244251
/**

0 commit comments

Comments
 (0)