mirror of https://github.com/buster-so/buster.git
Refactor undo-redo plugin using Plate.js shortcut API
Co-authored-by: nate <nate@buster.so>
This commit is contained in:
parent
521566349d
commit
f7155fbf23
|
@ -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;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue