From f600dec663dbc3b5ca8be2f4dddc97fc6b245b9a Mon Sep 17 00:00:00 2001 From: coderwei <65948611+coderwei99@users.noreply.github.com> Date: Sun, 31 Aug 2025 09:27:40 +0800 Subject: [PATCH] fix(hotkey): Prevent Arc browser undo on Cmd+Z in Drawnix (#254) * fix: Prevent Arc browser undo on Cmd+Z in Drawnix * fix(hotkey): prevent double undo on Cmd+Z by returning after handling * fix: prevent double undo --- packages/drawnix/src/plugins/with-hotkey.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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;