tiptap/packages/extension-history/index.ts

63 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-04-02 20:34:07 +08:00
import Editor, { Extension, CommandSpec } from '@tiptap/core'
2020-03-06 18:02:35 +08:00
import {
history,
undo,
redo,
undoDepth,
redoDepth,
} from 'prosemirror-history'
declare module '@tiptap/core/src/Editor' {
interface Editor {
undo(): Editor,
2020-04-02 19:36:18 +08:00
redo(): Editor,
2020-03-06 18:02:35 +08:00
}
}
export default class History extends Extension {
name = 'history'
2020-04-02 20:34:07 +08:00
commands(): CommandSpec {
return {
undo: (next, { view }) => {
undo(view.state, view.dispatch)
next()
},
redo: (next, { view }) => {
redo(view.state, view.dispatch)
next()
},
}
2020-03-06 18:02:35 +08:00
}
2020-04-02 19:36:18 +08:00
keys() {
return {
'Mod-z': () => this.editor.undo(),
'Mod-y': () => this.editor.redo(),
'Shift-Mod-z': () => this.editor.redo(),
}
}
2020-03-29 06:58:48 +08:00
plugins() {
2020-03-06 18:02:35 +08:00
return [
history()
]
}
// commands() {
// return {
2020-03-30 18:40:25 +08:00
// undo: (next, { view }) => {
// undo(view.state, view.dispatch)
// next()
// },
// redo: (next, { view }) => {
// redo(view.state, view.dispatch)
// next()
// },
// // undoDepth: () => undoDepth,
// // redoDepth: () => redoDepth,
2020-03-06 18:02:35 +08:00
// }
// }
}