mirror of https://github.com/buster-so/buster.git
Add undo/redo functionality to editor with keyboard shortcuts
Co-authored-by: nate <nate@buster.so>
This commit is contained in:
parent
e9fb9f0199
commit
521566349d
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
})
|
||||
];
|
Loading…
Reference in New Issue