fix: use pressed key rather than its code (#3978)
Co-authored-by: Joel Jacob Stephen <70131076+JoelJacobStephen@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
51412549e8
commit
08c655235d
@@ -132,30 +132,23 @@ function generateKeybindingString(ev: KeyboardEvent): ShortcutKey | null {
|
||||
|
||||
function getPressedKey(ev: KeyboardEvent): Key | null {
|
||||
// Sometimes the property code is not available on the KeyboardEvent object
|
||||
const val = (ev.code ?? "").toLowerCase()
|
||||
const key = (ev.key ?? "").toLowerCase()
|
||||
|
||||
// Check arrow keys
|
||||
if (val === "arrowup") return "up"
|
||||
else if (val === "arrowdown") return "down"
|
||||
else if (val === "arrowleft") return "left"
|
||||
else if (val === "arrowright") return "right"
|
||||
if (key.startsWith("arrow")) {
|
||||
return key.slice(5) as Key
|
||||
}
|
||||
|
||||
// Check letter keys
|
||||
const isLetter = val.startsWith("key")
|
||||
if (isLetter) return val.substring(3) as Key
|
||||
const isLetter = key.length === 1 && key >= "a" && key <= "z"
|
||||
if (isLetter) return key as Key
|
||||
|
||||
// Check if number keys
|
||||
const isDigit = val.startsWith("digit")
|
||||
if (isDigit) return val.substring(5) as Key
|
||||
const isDigit = key.length === 1 && key >= "0" && key <= "9"
|
||||
if (isDigit) return key as Key
|
||||
|
||||
// Check if slash
|
||||
if (val === "slash") return "/"
|
||||
|
||||
// Check if period
|
||||
if (val === "period") return "."
|
||||
|
||||
// Check if enter
|
||||
if (val === "enter") return "enter"
|
||||
// Check if slash, period or enter
|
||||
if (key === "/" || key === "." || key === "enter") return key
|
||||
|
||||
// If no other cases match, this is not a valid key
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user