From 521566349d784b57849f1ced6c30f20062a937e1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 8 Aug 2025 13:07:15 +0000 Subject: [PATCH] Add undo/redo functionality to editor with keyboard shortcuts Co-authored-by: nate --- .../src/components/ui/report/editor-kit.ts | 2 ++ .../ui/report/plugins/undo-redo-kit.tsx | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 apps/web/src/components/ui/report/plugins/undo-redo-kit.tsx diff --git a/apps/web/src/components/ui/report/editor-kit.ts b/apps/web/src/components/ui/report/editor-kit.ts index 6553f59eb..b5205dd42 100644 --- a/apps/web/src/components/ui/report/editor-kit.ts +++ b/apps/web/src/components/ui/report/editor-kit.ts @@ -37,6 +37,7 @@ import { TableKit } from './plugins/table-kit'; import { TocKit } from './plugins/toc-kit'; import { ToggleKit } from './plugins/toggle-kit'; import { BusterStreamKit } from './plugins/buster-stream-kit'; +import { UndoRedoKit } from './plugins/undo-redo-kit'; export const EditorKit = [ // Editing @@ -47,6 +48,7 @@ export const EditorKit = [ ...EmojiKit, ...ExitBreakKit, TrailingBlockPlugin, + ...UndoRedoKit, // Elements ...BasicBlocksKit, 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 new file mode 100644 index 000000000..c0b79ad75 --- /dev/null +++ b/apps/web/src/components/ui/report/plugins/undo-redo-kit.tsx @@ -0,0 +1,31 @@ +'use client'; + +import { isHotkey } from 'platejs'; +import { createPlatePlugin } 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(); + 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(); + editor.redo(); + return false; + } + + return true; + } + } + }) +]; \ No newline at end of file