Files
supabase/apps/studio/hooks/ui/useHotKey.ts
Saxon FletcherandJoshen Lim a224598f1e Decouple editor panel (#37707)
* decouple editor panel from global state

* refactor again

* dont close assistant

* remove async

* onsave props

* Fix TS errors

* Remove editorPanel state from app-state, use useHotKey hooks for keyboard shortcuts

* Minor UX improvements to EditorPanel

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-08-06 15:03:53 +07:00

21 lines
490 B
TypeScript

import { useEffect } from 'react'
export function useHotKey(
callback: (e: KeyboardEvent) => void,
key: string,
dependencies: any[] = []
): void {
useEffect(() => {
function handler(e: KeyboardEvent) {
if ((e.metaKey || e.ctrlKey) && e.key === key && !e.altKey && !e.shiftKey) {
callback(e)
}
}
window.addEventListener('keydown', handler)
return () => {
window.removeEventListener('keydown', handler)
}
}, [key, ...dependencies])
}