* Triggers a sequence's callback programmatically from devtools. * Creates a synthetic KeyboardEvent from the last key in the sequence. * * @param id - The registration ID to trigger * @returns True if the registration was found and triggered
(id: string)
| 586 | * @returns True if the registration was found and triggered |
| 587 | */ |
| 588 | triggerSequence(id: string): boolean { |
| 589 | const registration = this.#registrations.get(id) |
| 590 | if (!registration) { |
| 591 | return false |
| 592 | } |
| 593 | |
| 594 | const lastParsed = |
| 595 | registration.parsedSequence[registration.parsedSequence.length - 1] |
| 596 | if (!lastParsed) { |
| 597 | return false |
| 598 | } |
| 599 | |
| 600 | const syntheticEvent = new KeyboardEvent( |
| 601 | registration.options.eventType ?? 'keydown', |
| 602 | { |
| 603 | key: lastParsed.key, |
| 604 | ctrlKey: lastParsed.ctrl, |
| 605 | shiftKey: lastParsed.shift, |
| 606 | altKey: lastParsed.alt, |
| 607 | metaKey: lastParsed.meta, |
| 608 | bubbles: true, |
| 609 | cancelable: true, |
| 610 | }, |
| 611 | ) |
| 612 | |
| 613 | registration.triggerCount++ |
| 614 | registration.hasFired = true |
| 615 | |
| 616 | this.#syncRegistrationView(registration) |
| 617 | |
| 618 | const context: HotkeyCallbackContext = { |
| 619 | hotkey: registration.sequence.join(' ') as Hotkey, |
| 620 | parsedHotkey: lastParsed, |
| 621 | } |
| 622 | |
| 623 | registration.callback(syntheticEvent, context) |
| 624 | |
| 625 | return true |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Gets the number of registered sequences. |
no test coverage detected