Skip to content

Commit 75ec2c1

Browse files
committed
fix(web): HTML renders replay named keys only as their own shortcut
1 parent 31d3420 commit 75ec2c1

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎apps/web/src/components/files/BrowserDocumentFrame.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import {
1616
readHtmlRenderKeyDown,
1717
readHtmlRenderLinkRequest,
1818
} from "@t3tools/shared/htmlRender";
19-
import { isMacPlatform, matchesKeybindingShortcut } from "@t3tools/shared/keybindings";
19+
import {
20+
isMacPlatform,
21+
matchesKeybindingShortcut,
22+
normalizeEventKey,
23+
} from "@t3tools/shared/keybindings";
2024
import { useEffect, useEffectEvent, useLayoutEffect, useMemo, useRef, useState } from "react";
2125

2226
import { useOpenLink } from "~/browser/useOpenLink";
@@ -169,12 +173,20 @@ export function HtmlRenderDocument(props: {
169173
};
170174
useEffect(postShortcuts, [blocked, shortcuts]);
171175
// The page reports the key and code, and a page script can report any pair,
172-
// so a key that could match another command's binding is never replayed.
176+
// so a key that could match another command's binding is never replayed. A
177+
// named key (Backspace, Enter) must be the shortcut's own, since some app
178+
// handlers read `event.key` directly.
173179
const isShortcut = useEffectEvent(
174180
(key: NonNullable<ReturnType<typeof readHtmlRenderKeyDown>>) => {
175181
const matches = (shortcut: HtmlRenderShortcut) =>
176182
matchesKeybindingShortcut(key, { ...shortcut, modKey: false }, navigator.platform);
177-
return shortcuts.some(matches) && !blocked.some(matches);
183+
const allowed = shortcuts.filter(matches);
184+
return (
185+
allowed.length > 0 &&
186+
!blocked.some(matches) &&
187+
(key.key.length === 1 ||
188+
allowed.some((shortcut) => shortcut.key === normalizeEventKey(key.key)))
189+
);
178190
},
179191
);
180192
const openChangeRequestLink = useOpenChangeRequestLink(props.threadRef);

0 commit comments

Comments
 (0)