yjs / y-prosemirror

ProseMirror editor binding for Yjs

Home Page:https://demos.yjs.dev/prosemirror/prosemirror.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redo doesn't work in 1.1.0

ascott18 opened this issue · comments

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')
}
  1. Run the test

Expected behavior
Test Passes

Environment Information

  • Browser / Node.js [e.g. Chrome, Firefox, Node.js]: Chrome, Node.js
  • yjs 13.5.38
  • y-prosemirror 1.1.0

That was very helpful, thanks!

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