MCPcopy Create free account
hub / github.com/TanStack/hotkeys / createHotkeySequence

Function createHotkeySequence

packages/solid-hotkeys/src/createHotkeySequence.ts:64–155  ·  view source on GitHub ↗
(
  sequence: HotkeySequence | (() => HotkeySequence),
  callback: HotkeyCallback,
  options:
    | CreateHotkeySequenceOptions
    | (() => CreateHotkeySequenceOptions) = {},
)

Source from the content-addressed store, hash-verified

62 * ```
63 */
64export function createHotkeySequence(
65 sequence: HotkeySequence | (() => HotkeySequence),
66 callback: HotkeyCallback,
67 options:
68 | CreateHotkeySequenceOptions
69 | (() => CreateHotkeySequenceOptions) = {},
70): void {
71 const defaultOptions = useDefaultHotkeysOptions()
72 const manager = getSequenceManager()
73
74 let registration: SequenceRegistrationHandle | null = null
75 let lastSequenceKey: string | null = null
76 let lastTarget: HTMLElement | Document | Window | null = null
77
78 onCleanup(() => {
79 if (registration?.isActive) {
80 registration.unregister()
81 registration = null
82 }
83 lastSequenceKey = null
84 lastTarget = null
85 })
86
87 createEffect(() => {
88 // Resolve reactive values
89 const resolvedSequence =
90 typeof sequence === 'function' ? sequence() : sequence
91 const resolvedOptions = typeof options === 'function' ? options() : options
92
93 const mergedOptions = {
94 ...defaultOptions.hotkeySequence,
95 ...resolvedOptions,
96 } as CreateHotkeySequenceOptions
97
98 // Extract options without target (target is handled separately)
99 const { target: _target, ...optionsWithoutTarget } = mergedOptions
100
101 // Resolve target: when explicitly provided (even as null), use it and skip if null.
102 // When not provided, default to document. Matches createHotkey.
103 const resolvedTarget =
104 'target' in mergedOptions
105 ? (mergedOptions.target ?? null)
106 : typeof document !== 'undefined'
107 ? document
108 : null
109
110 if (resolvedSequence.length === 0 || !resolvedTarget) {
111 if (registration?.isActive) {
112 registration.unregister()
113 registration = null
114 }
115 lastSequenceKey = null
116 lastTarget = null
117 return
118 }
119
120 const sequenceKey = formatHotkeySequence(resolvedSequence)
121

Callers 1

AppFunction · 0.90

Calls 5

useDefaultHotkeysOptionsFunction · 0.90
getSequenceManagerFunction · 0.90
formatHotkeySequenceFunction · 0.90
setOptionsMethod · 0.45
registerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…