diff --git a/packages/drawnix/src/plugins/with-hotkey.ts b/packages/drawnix/src/plugins/with-hotkey.ts index 412a0c72..d0a0d4c6 100644 --- a/packages/drawnix/src/plugins/with-hotkey.ts +++ b/packages/drawnix/src/plugins/with-hotkey.ts @@ -17,7 +17,7 @@ export const buildDrawnixHotkeyPlugin = ( updateAppState: (appState: Partial) => void ) => { const withDrawnixHotkey = (board: PlaitBoard) => { - const { globalKeyDown } = board; + const { globalKeyDown, keyDown } = board; board.globalKeyDown = (event: KeyboardEvent) => { const isTypingNormal = event.target instanceof HTMLInputElement || @@ -100,6 +100,22 @@ export const buildDrawnixHotkeyPlugin = ( globalKeyDown(event); }; + board.keyDown = (event: KeyboardEvent) => { + if (isHotkey(['mod+z'], { byKey: true })(event)) { + board.undo(); + event.preventDefault(); + return; + } + + if (isHotkey(['mod+shift+z'], { byKey: true })(event)) { + board.redo(); + event.preventDefault(); + return; + } + + keyDown(event); + }; + return board; }; return withDrawnixHotkey;