MCPcopy Create free account
hub / github.com/github/hotkey / SequenceTracker

Class SequenceTracker

src/sequence.ts:17–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15export type NormalizedSequenceString = string & {[sequenceBrand]: true}
16
17export class SequenceTracker {
18 static readonly CHORD_TIMEOUT = 1500
19
20 private _path: readonly NormalizedHotkeyString[] = []
21 private timer: number | null = null
22 private onReset
23
24 constructor({onReset}: SequenceTrackerOptions = {}) {
25 this.onReset = onReset
26 }
27
28 get path(): readonly NormalizedHotkeyString[] {
29 return this._path
30 }
31
32 get sequence(): NormalizedSequenceString {
33 return this._path.join(SEQUENCE_DELIMITER) as NormalizedSequenceString
34 }
35
36 registerKeypress(event: KeyboardEvent): void {
37 this._path = [...this._path, eventToHotkeyString(event)]
38 this.startTimer()
39 }
40
41 reset(): void {
42 this.killTimer()
43 this._path = []
44 this.onReset?.()
45 }
46
47 private killTimer(): void {
48 if (this.timer != null) {
49 window.clearTimeout(this.timer)
50 }
51 this.timer = null
52 }
53
54 private startTimer(): void {
55 this.killTimer()
56 this.timer = window.setTimeout(() => this.reset(), SequenceTracker.CHORD_TIMEOUT)
57 }
58}
59
60export function normalizeSequence(sequence: string): NormalizedSequenceString {
61 return sequence

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…