mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +08:00
fix can().undo() for collab
This commit is contained in:
parent
9f0715ebff
commit
bd621f4677
@ -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',
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user