MCPcopy Create free account
hub / github.com/rhysd/Tui / registerKeymap

Method registerKeymap

webview/keymaps_handler.ts:68–94  ·  view source on GitHub ↗
(key: string, name: KeymapName | null)

Source from the content-addressed store, hash-verified

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;

Callers 1

subscribeKeydownMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected