fix can().undo() for collab
This commit is contained in:
@@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user