add collab commands

This commit is contained in:
Philipp Kühn
2020-12-02 09:28:55 +01:00
parent 5b794c9137
commit 143b309bdf
2 changed files with 30 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import { Extension } from '@tiptap/core'
import { Extension, Command } from '@tiptap/core'
import {
redo,
undo,
@@ -15,6 +15,31 @@ const Collaboration = Extension.create({
provider: null,
},
addCommands() {
return {
/**
* Undo recent changes
*/
undo: (): Command => ({ state }) => {
return undo(state)
},
/**
* Reapply reverted changes
*/
redo: (): Command => ({ state }) => {
return redo(state)
},
}
},
addKeyboardShortcuts() {
return {
'Mod-z': () => this.editor.commands.undo(),
'Mod-y': () => this.editor.commands.redo(),
'Shift-Mod-z': () => this.editor.commands.redo(),
}
},
addProseMirrorPlugins() {
return [
ySyncPlugin(
@@ -24,14 +49,6 @@ const Collaboration = Extension.create({
]
},
addKeyboardShortcuts() {
return {
'Mod-z': () => undo(this.editor.state),
'Mod-y': () => redo(this.editor.state),
'Mod-Shift-z': () => redo(this.editor.state),
}
},
onDestroy() {
this.options.provider?.destroy()
},