yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
328 stars 115 forks source link

Redo doesn't work in 1.1.0 #115

Closed ascott18 closed 2 years ago

ascott18 commented 2 years ago

Checklist

Describe the bug Redo no longer works in 1.1.0. UndoManager.afterTransactionHandler does not run when performing the undo because captureTransaction returns false. Since afterTransactionHandler does not run, the redoStack never gets filled with the undo operation.

To Reproduce Steps to reproduce the behavior:

  1. Modify testAddToHistory to also test redo:
    export const testAddToHistory = tc => {
    const ydoc = new Y.Doc()
    const view = createNewProsemirrorViewWithUndoManager(ydoc)
    view.dispatch(view.state.tr.insert(0, /** @type {any} */ (schema.node('paragraph', undefined, schema.text('123')))))
    const yxml = ydoc.get('prosemirror')
    t.assert(yxml.length === 2 && yxml.get(0).length === 1, 'contains inserted content')
    undo(view.state)
    t.assert(yxml.length === 0, 'insertion was undone')
    redo(view.state)  
    t.assert(yxml.length === 2 && yxml.get(0).length === 1, 'contains inserted content')  
    undo(view.state)  
    t.assert(yxml.length === 0, 'insertion was undone')  
    // now insert content again, but with `'addToHistory': false`
    view.dispatch(view.state.tr.insert(0, /** @type {any} */ (schema.node('paragraph', undefined, schema.text('123')))).setMeta('addToHistory', false))
    t.assert(yxml.length === 2 && yxml.get(0).length === 1, 'contains inserted content')
    undo(view.state)
    t.assert(yxml.length === 2 && yxml.get(0).length === 1, 'insertion was *not* undone')
    }
  2. Run the test

Expected behavior Test Passes

Environment Information

dmonad commented 2 years ago

That was very helpful, thanks!

Gonna publish a new release with a fix in a bit.