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
This commit is contained in:
coderwei authored and GitHub committed 2025-08-31 09:27:40 +08:00
1 parent b5d38f3d9f
commit f600dec663
1 file changed
+17 -1
+17 -1
View File
@@ -17,7 +17,7 @@ export const buildDrawnixHotkeyPlugin = (
updateAppState: (appState: Partial<DrawnixState>) => 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;