@@ -22,7 +22,7 @@ import {
2222 matchesKeybindingShortcut ,
2323 normalizeEventKey ,
2424} from "@t3tools/shared/keybindings" ;
25- import { useEffect , useEffectEvent , useLayoutEffect , useMemo , useRef , useState } from "react" ;
25+ import { useEffect , useEffectEvent , useLayoutEffect , useRef , useState } from "react" ;
2626
2727import { useOpenLink } from "~/browser/useOpenLink" ;
2828import { ExpandedImageDialog } from "~/components/chat/ExpandedImageDialog" ;
@@ -135,29 +135,27 @@ export function HtmlRenderDocument(props: {
135135 // binding counts whatever its `when`, and a key that any binding gives to
136136 // another command stays with the page. Only Cmd/Ctrl chords: a printable key
137137 // would type into the composer instead.
138- const { shortcuts, blocked } = useMemo ( ( ) => {
139- const mac = isMacPlatform ( navigator . platform ) ;
140- const resolve = ( shortcut : KeybindingShortcut ) : HtmlRenderShortcut => ( {
141- key : shortcut . key ,
142- metaKey : shortcut . metaKey || ( shortcut . modKey && mac ) ,
143- ctrlKey : shortcut . ctrlKey || ( shortcut . modKey && ! mac ) ,
144- shiftKey : shortcut . shiftKey ,
145- altKey : shortcut . altKey ,
146- } ) ;
147- const blocked = [ ...keybindings , ...( environmentKeybindings ?? [ ] ) ]
148- . filter ( ( binding ) => ! HTML_RENDER_SHORTCUT_COMMANDS . has ( binding . command ) )
149- . map ( ( binding ) => resolve ( binding . shortcut ) ) ;
150- const shortcuts = new Map < string , HtmlRenderShortcut > ( ) ;
151- for ( const { command, shortcut } of keybindings ) {
152- if (
153- HTML_RENDER_SHORTCUT_COMMANDS . has ( command ) &&
154- ( shortcut . metaKey || shortcut . ctrlKey || shortcut . modKey )
155- ) {
156- shortcuts . set ( shortcutConflictKey ( shortcut ) , resolve ( shortcut ) ) ;
157- }
138+ const mac = isMacPlatform ( navigator . platform ) ;
139+ const resolve = ( shortcut : KeybindingShortcut ) : HtmlRenderShortcut => ( {
140+ key : shortcut . key ,
141+ metaKey : shortcut . metaKey || ( shortcut . modKey && mac ) ,
142+ ctrlKey : shortcut . ctrlKey || ( shortcut . modKey && ! mac ) ,
143+ shiftKey : shortcut . shiftKey ,
144+ altKey : shortcut . altKey ,
145+ } ) ;
146+ const blocked = [ ...keybindings , ...( environmentKeybindings ?? [ ] ) ]
147+ . filter ( ( binding ) => ! HTML_RENDER_SHORTCUT_COMMANDS . has ( binding . command ) )
148+ . map ( ( binding ) => resolve ( binding . shortcut ) ) ;
149+ const shortcutsByKey = new Map < string , HtmlRenderShortcut > ( ) ;
150+ for ( const { command, shortcut } of keybindings ) {
151+ if (
152+ HTML_RENDER_SHORTCUT_COMMANDS . has ( command ) &&
153+ ( shortcut . metaKey || shortcut . ctrlKey || shortcut . modKey )
154+ ) {
155+ shortcutsByKey . set ( shortcutConflictKey ( shortcut ) , resolve ( shortcut ) ) ;
158156 }
159- return { shortcuts : [ ... shortcuts . values ( ) ] , blocked } ;
160- } , [ environmentKeybindings , keybindings ] ) ;
157+ }
158+ const shortcuts = [ ... shortcutsByKey . values ( ) ] ;
161159 const postShortcuts = ( ) => {
162160 frameRef . current ?. contentWindow ?. postMessage (
163161 htmlRenderShortcutsMessage ( shortcuts , blocked ) ,
0 commit comments