MCPcopy Create free account
hub / github.com/GCWing/BitFun / useShortcut

Function useShortcut

src/web-ui/src/infrastructure/hooks/useShortcut.ts:25–62  ·  view source on GitHub ↗
(
  id: string,
  config: ShortcutConfig,
  callback: ShortcutCallback,
  options: UseShortcutOptions = {}
)

Source from the content-addressed store, hash-verified

23 * @param options Optional description, priority, enabled flag
24 */
25export function useShortcut(
26 id: string,
27 config: ShortcutConfig,
28 callback: ShortcutCallback,
29 options: UseShortcutOptions = {}
30): void {
31 const { description, priority, enabled = true } = options;
32
33 // Keep the latest callback in a ref so changes don't trigger re-registration.
34 const callbackRef = useRef<ShortcutCallback>(callback);
35 callbackRef.current = callback;
36
37 // Stable wrapper that delegates to the current callback ref.
38 const stableCallback = useRef<ShortcutCallback>((e) => callbackRef.current(e));
39
40 // Serialize config to a stable string for the dependency array.
41 const configKey = JSON.stringify({
42 key: config.key,
43 ctrl: config.ctrl,
44 shift: config.shift,
45 alt: config.alt,
46 meta: config.meta,
47 scope: config.scope,
48 allowInInput: config.allowInInput,
49 });
50
51 useEffect(() => {
52 if (!enabled) return;
53
54 const unregister = shortcutManager.register(id, config, stableCallback.current, {
55 description,
56 priority,
57 });
58
59 return unregister;
60 // eslint-disable-next-line react-hooks/exhaustive-deps
61 }, [id, configKey, enabled, description, priority]);
62}

Callers 8

FileExplorerFunction · 0.90
AppFunction · 0.90
AppLayoutFunction · 0.90
MainNavFunction · 0.90
useKeyboardShortcutsFunction · 0.90
WorkingCopyViewFunction · 0.90
useGlobalSceneShortcutsFunction · 0.90
ModernFlowChatContainerFunction · 0.90

Calls 3

stringifyMethod · 0.80
currentMethod · 0.45
registerMethod · 0.45

Tested by

no test coverage detected