You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'd like to add support for lifecycle callbacks on sequences.
Specifically, I want to create transient UI like a "press the next key…" overlay that shows up the moment the user starts a sequence and disappears the moment they bail or time out.
I believe, today the only signal is the completion callback. The best way I could find to achieve this today would be subscribing to the manager's store.
I'd be happy to create PR.
API proposal
Three new optional fields on SequenceOptions:
exportinterfaceSequenceCancelContext{/** The original hotkey sequence joined with spaces. */hotkey: Hotkey/** The last successfully matched step in the cancelled attempt. */parsedHotkey: ParsedHotkey/** How many steps were matched before the cancellation (between 1 and `sequence.length - 1`). */matchedStepCount: number/** Reason why sequence was cancelled */reason: "timeout"|"interrupt"| ...
/** Optional keyboard event that canceled the sequence. (This is attached to context so we can discriminate the types based on reason) */event: KeyboardEvent|undefined}interfaceSequenceOptions{// ...existingonStart?: (event: KeyboardEvent,context: HotkeyCallbackContext)=>voidonCancel?: (context: SequenceCancelContext)=>void}
onStart fires when a multi-step sequence advances past its first step. Single-step sequences don't fire it (they complete immediately).
onCancel fires when the configured timeout between steps elapses without further input, or when the sequence is interrupted. Sequence can be interrupted by when a non-matching key arrives mid-sequence, or when something changes programmatically (such as enabled flipping from true to false)
Right now, "timeout" is only checked when another key is pressed. To track onCancel callback, we'd have to schedule actual timeout via setTimeout. To keep the overhead to minimal, we only schedule it when onCancel is actually provided.
I also considered returning sort of inProgress state from the hook, but I don't believe this is correct solution, as we'd be paying the overhead even when 99% of usecases don't need it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'd like to add support for lifecycle callbacks on sequences.
Specifically, I want to create transient UI like a "press the next key…" overlay that shows up the moment the user starts a sequence and disappears the moment they bail or time out.
I believe, today the only signal is the completion callback. The best way I could find to achieve this today would be subscribing to the manager's store.
I'd be happy to create PR.
API proposal
Three new optional fields on
SequenceOptions:onStartfires when a multi-step sequence advances past its first step. Single-step sequences don't fire it (they complete immediately).onCancelfires when the configuredtimeoutbetween steps elapses without further input, or when the sequence is interrupted. Sequence can be interrupted by when a non-matching key arrives mid-sequence, or when something changes programmatically (such asenabledflipping fromtruetofalse)Right now, "timeout" is only checked when another key is pressed. To track
onCancelcallback, we'd have to schedule actual timeout viasetTimeout. To keep the overhead to minimal, we only schedule it whenonCancelis actually provided.I also considered returning sort of
inProgressstate from the hook, but I don't believe this is correct solution, as we'd be paying the overhead even when 99% of usecases don't need it.Beta Was this translation helpful? Give feedback.
All reactions