fix can().undo() for collab

This commit is contained in:
Philipp Kühn
2021-02-22 10:40:56 +01:00
parent 9f0715ebff
commit bd621f4677
2 changed files with 25 additions and 2 deletions

View File

@@ -1,9 +1,11 @@
import { Extension, Command } from '@tiptap/core'
import { UndoManager } from 'yjs'
import {
redo,
undo,
ySyncPlugin,
yUndoPlugin,
yUndoPluginKey,
} from 'y-prosemirror'
declare module '@tiptap/core' {
@@ -47,14 +49,34 @@ export const Collaboration = Extension.create<CollaborationOptions>({
addCommands() {
return {
undo: () => ({ tr, state }) => {
undo: () => ({ tr, state, dispatch }) => {
tr.setMeta('preventDispatch', true)
const undoManager: UndoManager = yUndoPluginKey.getState(state).undoManager
if (undoManager.undoStack.length === 0) {
return false
}
if (!dispatch) {
return true
}
return undo(state)
},
redo: () => ({ tr, state }) => {
redo: () => ({ tr, state, dispatch }) => {
tr.setMeta('preventDispatch', true)
const undoManager: UndoManager = yUndoPluginKey.getState(state).undoManager
if (undoManager.redoStack.length === 0) {
return false
}
if (!dispatch) {
return true
}
return redo(state)
},
}