Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/core/src/features/hotkeys-core/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
} from "../../types/core";
import { HotkeyConfig, HotkeysCoreDataRef } from "./types";

// e.code may be empty or "Unidentified" on mobile virtual keyboards
// or during IME composition, so we fall back to e.key
const resolveKeyCode = (e: KeyboardEvent): string =>
e.code !== "" && e.code !== "Unidentified" ? e.code : e.key;

const specialKeys: Record<string, RegExp> = {
// TODO:breaking deprecate auto-lowercase
letter: /^Key[A-Z]$/,
Expand Down Expand Up @@ -71,9 +76,11 @@ export const hotkeysCoreFeature: FeatureImplementation = {
return;
}

const resolvedCode = resolveKeyCode(e);

data.current.pressedKeys ??= new Set();
const newMatch = !data.current.pressedKeys.has(e.code);
data.current.pressedKeys.add(e.code);
const newMatch = !data.current.pressedKeys.has(resolvedCode);
data.current.pressedKeys.add(resolvedCode);

const hotkeyName = findHotkeyMatch(
data.current.pressedKeys,
Expand All @@ -85,7 +92,7 @@ export const hotkeysCoreFeature: FeatureImplementation = {
if (e.target instanceof HTMLInputElement) {
// JS respects composite keydowns while input elements are focused, and
// doesnt send the associated keyup events with the same key name
data.current.pressedKeys.delete(e.code);
data.current.pressedKeys.delete(resolvedCode);
}

if (!hotkeyName) return;
Expand All @@ -110,7 +117,7 @@ export const hotkeysCoreFeature: FeatureImplementation = {

const keyup = (e: KeyboardEvent) => {
data.current.pressedKeys ??= new Set();
data.current.pressedKeys.delete(e.code);
data.current.pressedKeys.delete(resolveKeyCode(e));
};

const reset = () => {
Expand Down
Loading