| 66 | } |
| 67 | |
| 68 | registerKeymap(key: string, name: KeymapName | null) { |
| 69 | if (!name) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (!this[name]) { |
| 74 | Mousetrap.bind(key, e => { |
| 75 | e.preventDefault(); |
| 76 | console.log('Tui: Keydown: Custom action: ' + key, name, e); |
| 77 | const handle = this.customHandlers[name as string]; |
| 78 | if (!handle) { |
| 79 | console.error('Tui: No custom handler found for the action:', name); |
| 80 | return; |
| 81 | } |
| 82 | handle(this.context, e); |
| 83 | }); |
| 84 | } else { |
| 85 | const method = this[name].bind(this); |
| 86 | Mousetrap.bind(key, e => { |
| 87 | e.preventDefault(); |
| 88 | console.log('Tui: Keydown: ' + key, name, e); |
| 89 | // Note: Need not to pass context because they can refer context |
| 90 | // via this.context. |
| 91 | method(e); |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | registerCustomHandler(name: string, handler: CustomHandler) { |
| 97 | this.customHandlers[name] = handler; |