From f7155fbf2372e43418b324377258a88239798f3b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 8 Aug 2025 13:16:13 +0000 Subject: [PATCH] Refactor undo-redo plugin using Plate.js shortcut API Co-authored-by: nate --- .../ui/report/plugins/undo-redo-kit.tsx | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/ui/report/plugins/undo-redo-kit.tsx b/apps/web/src/components/ui/report/plugins/undo-redo-kit.tsx index c0b79ad75..33e9794cf 100644 --- a/apps/web/src/components/ui/report/plugins/undo-redo-kit.tsx +++ b/apps/web/src/components/ui/report/plugins/undo-redo-kit.tsx @@ -1,30 +1,27 @@ 'use client'; -import { isHotkey } from 'platejs'; -import { createPlatePlugin } from 'platejs/react'; +import { createPlatePlugin, Key } from 'platejs/react'; export const UNDO_REDO_KIT_KEY = 'undo-redo'; export const UndoRedoKit = [ - createPlatePlugin({ - key: UNDO_REDO_KIT_KEY, - handlers: { - onKeyDown: ({ editor, event }) => { - // Undo: mod+z (Cmd+Z on macOS, Ctrl+Z on Windows/Linux) - if (isHotkey('mod+z')(event)) { - event.preventDefault(); + createPlatePlugin({ key: UNDO_REDO_KIT_KEY }).extend({ + shortcuts: { + undo: { + keys: [[Key.Mod, 'z']], + handler: ({ editor }) => { editor.undo(); - return false; } - - // Redo: mod+shift+z (common on macOS) or mod+y (common on Windows/Linux) - if (isHotkey('mod+shift+z')(event) || isHotkey('mod+y')(event)) { - event.preventDefault(); + }, + redo: { + // Support both common redo shortcuts + keys: [ + [Key.Mod, Key.Shift, 'z'], + [Key.Mod, 'y'] + ], + handler: ({ editor }) => { editor.redo(); - return false; } - - return true; } } })