⚡ (editor) Add Ctrl + z shortcut to undo changes in editor (#255)
Closes #217
This commit is contained in:
18
apps/builder/src/hooks/useUndoShortcut.ts
Normal file
18
apps/builder/src/hooks/useUndoShortcut.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useEventListener } from '@chakra-ui/react'
|
||||
|
||||
export const useUndoShortcut = (undo: () => void) => {
|
||||
const isUndoShortcut = (event: KeyboardEvent) =>
|
||||
(event.metaKey || event.ctrlKey) && event.key === 'z'
|
||||
|
||||
useEventListener('keydown', (event: KeyboardEvent) => {
|
||||
const target = event.target as HTMLElement | null
|
||||
const isTyping =
|
||||
target?.role === 'textbox' ||
|
||||
target instanceof HTMLTextAreaElement ||
|
||||
target instanceof HTMLInputElement
|
||||
if (isTyping) return
|
||||
if (isUndoShortcut(event)) {
|
||||
undo()
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user