2
0

(editor) Add Ctrl + z shortcut to undo changes in editor (#255)

Closes #217
This commit is contained in:
Jorgelig
2023-01-17 10:01:12 -06:00
committed by GitHub
parent 930fef2c34
commit c711f3660f
2 changed files with 39 additions and 2 deletions

View 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()
}
})
}