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

@ -59,6 +59,7 @@ module.exports = {
'no-param-reassign': 'off',
'import/prefer-default-export': 'off',
'consistent-return': 'off',
'prefer-destructuring': 'off',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': ['error'],
'no-unused-vars': 'off',

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)
},
}