(character: string, modifiers: string[], e: KeyboardEvent)
| 534 | } |
| 535 | |
| 536 | private handleKey(character: string, modifiers: string[], e: KeyboardEvent): void { |
| 537 | const callbacks: HotkeyCallbackConfig[] = this.getMatches(character, modifiers, e) |
| 538 | let i: number |
| 539 | const doNotReset: SequenceLevels = {} |
| 540 | let maxLevel = 0 |
| 541 | let processedSequenceCallback = false |
| 542 | |
| 543 | // Calculate the maxLevel for sequences so we can only execute the longest callback sequence |
| 544 | for (i = 0; i < callbacks.length; ++i) { |
| 545 | if (callbacks[i].seq) { |
| 546 | maxLevel = Math.max(maxLevel, callbacks[i].level || 0) |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | // loop through matching callbacks for this key event |
| 551 | for (i = 0; i < callbacks.length; ++i) { |
| 552 | // fire for all sequence callbacks |
| 553 | // this is because if for example you have multiple sequences |
| 554 | // bound such as "g i" and "g t" they both need to fire the |
| 555 | // callback for matching g cause otherwise you can only ever |
| 556 | // match the first one |
| 557 | if (callbacks[i].seq) { |
| 558 | // only fire callbacks for the maxLevel to prevent |
| 559 | // subsequences from also firing |
| 560 | // |
| 561 | // for example 'a option b' should not cause 'option b' to fire |
| 562 | // even though 'option b' is part of the other sequence |
| 563 | // |
| 564 | // any sequences that do not match here will be discarded |
| 565 | // below by the resetSequences call |
| 566 | if (callbacks[i].level !== maxLevel) { |
| 567 | continue |
| 568 | } |
| 569 | |
| 570 | processedSequenceCallback = true |
| 571 | |
| 572 | // keep a list of which sequences were matches for later |
| 573 | doNotReset[callbacks[i].seq || ''] = 1 |
| 574 | fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq) |
| 575 | continue |
| 576 | } |
| 577 | |
| 578 | // if there were no sequence matches but we are still here |
| 579 | // that means this is a regular match so we should fire that |
| 580 | if (!processedSequenceCallback) { |
| 581 | fireCallback(callbacks[i].callback, e, callbacks[i].combo) |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | const ignoreThisKeypress = e.type === 'keypress' && this.ignoreNextKeypress |
| 586 | if (e.type === this.nextExpectedAction && !isModifier(character) && !ignoreThisKeypress) { |
| 587 | this.resetSequences(doNotReset) |
| 588 | } |
| 589 | |
| 590 | this.ignoreNextKeypress = processedSequenceCallback && e.type === 'keydown' |
| 591 | } |
| 592 | |
| 593 | private handleKeyEvent(e: KeyboardEvent): void { |
no test coverage detected