add collab commands
This commit is contained in:
@@ -53,7 +53,9 @@ export default class CommandManager {
|
|||||||
const method = (...args: any) => {
|
const method = (...args: any) => {
|
||||||
const callback = command(...args)(props)
|
const callback = command(...args)(props)
|
||||||
|
|
||||||
|
if (tr.steps.length) {
|
||||||
view.dispatch(tr)
|
view.dispatch(tr)
|
||||||
|
}
|
||||||
|
|
||||||
return callback
|
return callback
|
||||||
}
|
}
|
||||||
@@ -72,7 +74,7 @@ export default class CommandManager {
|
|||||||
return new Proxy({}, {
|
return new Proxy({}, {
|
||||||
get: (_, name: string, proxy) => {
|
get: (_, name: string, proxy) => {
|
||||||
if (name === 'run') {
|
if (name === 'run') {
|
||||||
if (!hasStartTransaction && shouldDispatch) {
|
if (!hasStartTransaction && shouldDispatch && tr.steps.length) {
|
||||||
view.dispatch(tr)
|
view.dispatch(tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Extension } from '@tiptap/core'
|
import { Extension, Command } from '@tiptap/core'
|
||||||
import {
|
import {
|
||||||
redo,
|
redo,
|
||||||
undo,
|
undo,
|
||||||
@@ -15,6 +15,31 @@ const Collaboration = Extension.create({
|
|||||||
provider: null,
|
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() {
|
addProseMirrorPlugins() {
|
||||||
return [
|
return [
|
||||||
ySyncPlugin(
|
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() {
|
onDestroy() {
|
||||||
this.options.provider?.destroy()
|
this.options.provider?.destroy()
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user