From 7e9a78898fb465da8bd5d693a1b6b84e2922cfa2 Mon Sep 17 00:00:00 2001 From: York Date: Mon, 1 Jun 2026 13:43:58 +0800 Subject: [PATCH] fix: punctuation hotkeys not captured (#2091) --- src/shared/utils/hotkeys.ts | 19 +++++++++++++++++++ src/shared/utils/keyboard-code-to-hotkey.ts | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/shared/utils/hotkeys.ts b/src/shared/utils/hotkeys.ts index 4e51006b6..a12667fb2 100644 --- a/src/shared/utils/hotkeys.ts +++ b/src/shared/utils/hotkeys.ts @@ -2,6 +2,20 @@ import type { HotkeyItem } from '@mantine/hooks'; const RESERVED_KEYS = new Set(['alt', 'ctrl', 'meta', 'mod', 'shift']); +const PUNCTUATION_KEY_TO_PHYSICAL: Record = { + "'": 'Quote', + ',': 'Comma', + '-': 'Minus', + '.': 'Period', + '/': 'Slash', + ';': 'Semicolon', + '=': 'Equal', + '[': 'BracketLeft', + '\\': 'Backslash', + ']': 'BracketRight', + '`': 'Backquote', +}; + /** * Converts stored hotkey strings to Mantine's physical-key format. * Mantine matches KeyboardEvent.code via normalizeKey, which turns Digit1 into @@ -25,6 +39,11 @@ export const toPhysicalHotkey = (hotkey: string): string => return `Digit${part}`; } + const punctuationPhysical = PUNCTUATION_KEY_TO_PHYSICAL[part]; + if (punctuationPhysical) { + return punctuationPhysical; + } + return part; }) .join('+'); diff --git a/src/shared/utils/keyboard-code-to-hotkey.ts b/src/shared/utils/keyboard-code-to-hotkey.ts index e33dbbd74..a9d3f9f0f 100644 --- a/src/shared/utils/keyboard-code-to-hotkey.ts +++ b/src/shared/utils/keyboard-code-to-hotkey.ts @@ -3,7 +3,12 @@ const CODE_TO_HOTKEY_KEY: Record = { ArrowLeft: 'arrowleft', ArrowRight: 'arrowright', ArrowUp: 'arrowup', + Backquote: '`', + Backslash: '\\', Backspace: 'backspace', + BracketLeft: '[', + BracketRight: ']', + Comma: ',', Delete: 'delete', End: 'end', Enter: 'enter', @@ -14,6 +19,10 @@ const CODE_TO_HOTKEY_KEY: Record = { Minus: 'minus', PageDown: 'pagedown', PageUp: 'pageup', + Period: '.', + Quote: "'", + Semicolon: ';', + Slash: '/', Space: 'space', Tab: 'tab', };