| Action | Default | Custom | |--------|---------|--------| | Save | Ctrl+S | (click to record) | | New File | Ctrl+N | Ctrl+Shift+N | | Find | Ctrl+F | F3 |
private matches(pressed: string, bindingKeys: string[]): boolean return bindingKeys.some(k => this.normalizeKeyString(k) === pressed); keybinding
function useKeybinding(id: string, callback: () => void, deps: any[] = []) const manager = useKeybindingManager(); // from context useEffect(() => manager.on(id, callback); return () => manager.off(id, callback); , [id, callback, ...deps]); | Action | Default | Custom | |--------|---------|--------|
setContext(context: string) this.activeContext = context; this.normalizeKeyString(k) === pressed)
on(id: string, callback: () => void) if (!this.listeners.has(id)) this.listeners.set(id, new Set()); this.listeners.get(id)!.add(callback);
function Editor() useKeybinding("save", () => console.log("Saved via Ctrl+S"); ); return <textarea />;
private trigger(id: string) const callbacks = this.listeners.get(id); callbacks?.forEach(cb => cb());