* Register shortcut * * @param shortcut - shortcut options
(shortcut: ShortcutData)
| 51 | * @param shortcut - shortcut options |
| 52 | */ |
| 53 | public add(shortcut: ShortcutData): void { |
| 54 | const foundShortcut = this.findShortcut(shortcut.on, shortcut.name); |
| 55 | |
| 56 | if (foundShortcut) { |
| 57 | throw Error( |
| 58 | `Shortcut ${shortcut.name} is already registered for ${shortcut.on}. Please remove it before add a new handler.` |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | const newShortcut = new Shortcut({ |
| 63 | name: shortcut.name, |
| 64 | on: shortcut.on, |
| 65 | callback: shortcut.handler, |
| 66 | }); |
| 67 | const shortcuts = this.registeredShortcuts.get(shortcut.on) || []; |
| 68 | |
| 69 | this.registeredShortcuts.set(shortcut.on, [...shortcuts, newShortcut]); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Remove shortcut |
no test coverage detected