Last active
January 12, 2025 19:11
-
-
Save ova2/1683f3ec744a5ee191f9961115c86c4e to your computer and use it in GitHub Desktop.
shortcut$
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shortcut$(...shortcutKeys: ShortcutKey[]): Observable<KeyboardEvent[] | undefined> { | |
const keyCodes: string[][] = shortcutKeys.map(shortcutKey => | |
Array.isArray(shortcutKey.keyCode) ? shortcutKey.keyCode : [shortcutKey.keyCode]); | |
if (keyCodes.length === 1 && keyCodes[0].length === 1) { | |
// small optimization for a single key binding | |
return this.singleShortcut$(keyCodes[0]); | |
} | |
const keyCodesAsCartesianProduct = [...this.cartesianIterator(keyCodes)]; | |
const arr$: Observable<KeyboardEvent[] | undefined>[] = | |
keyCodesAsCartesianProduct.map(k => this.singleShortcut$(k)); | |
return merge(...arr$); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment