Skip to content

Commit

Permalink
feat(builder): Enable ctrl+z to undo changes in editor#217
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorgelig committed Jan 16, 2023
1 parent 65c35fa commit e547cbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { headerHeight } from '../../constants'
import { EditableEmojiOrImageIcon } from '@/components/EditableEmojiOrImageIcon'
import { PublishButton } from '@/features/publish'
import { CollaborationMenuButton } from '@/features/collaboration'
import { useUndoShortcut } from '@/hooks/useUndoShortcut'


export const TypebotHeader = () => {
const router = useRouter()
Expand All @@ -52,6 +54,8 @@ export const TypebotHeader = () => {
setRightPanel(RightPanel.PREVIEW)
}

useUndoShortcut(canUndo, undo);

const handleHelpClick = () => {
isCloudProdInstance
? getBubbleActions().open()
Expand Down
12 changes: 12 additions & 0 deletions apps/builder/src/hooks/useUndoShortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEventListener } from '@chakra-ui/react'

export const useUndoShortcut = (canUndo: boolean, undo: () => void) => {
const isUndoShortcut = (event: KeyboardEvent) =>
(event.metaKey || event.ctrlKey) && event.key === 'z'

useEventListener('keydown', (event: KeyboardEvent) => {
if (isUndoShortcut(event) && canUndo) {
undo()
}
})
}

0 comments on commit e547cbb

Please sign in to comment.