Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo stack loses info after undo followed by new insertion #4

Closed
2 tasks done
andrewheumann opened this issue Mar 29, 2023 · 4 comments
Closed
2 tasks done

Undo stack loses info after undo followed by new insertion #4

andrewheumann opened this issue Mar 29, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@andrewheumann
Copy link

Checklist

Describe the bug
After a sequence where we:

  • add some changes
  • undo a single change
  • add another individual change
    we are no longer able to undo back past the previous undo.

To Reproduce
Here is a test which demonstrates the issue:

/**
 * @param {t.TestCase} tc
 */
export const testUndoAfterChangeAfterUndo = tc => {
  const um = new YMultiDocUndoManager()
  const ydoc1 = new Y.Doc()
  const ytype1 = ydoc1.getText()
  um.addToScope([ytype1])

  ytype1.insert(0, 'a')

  t.assert(ytype1.toString() === 'a')
  t.assert(um.undoStack.length === 1)

  ytype1.insert(1, 'b')

  t.assert(ytype1.toString() === 'ab')
  t.assert(um.undoStack.length === 2)

  ytype1.insert(2, 'c')

  t.assert(ytype1.toString() === 'abc')
  t.assert(um.undoStack.length === 3)

  um.undo()

  t.assert(ytype1.toString() === 'ab')
  t.assert(um.undoStack.length === 2)

  ytype1.insert(2, 'x')

  t.assert(ytype1.toString() === 'abx')
  t.assert(um.undoStack.length === 3) // This is 1, instead of 3

  um.undo()

  t.assert(ytype1.toString() === 'ab')
  t.assert(um.undoStack.length === 2)

  um.undo() // this undo would be unavailable

  t.assert(ytype1.toString() === 'a')
  t.assert(um.undoStack.length === 1)
}

Expected behavior
I expect to be able to continue to undo back through the entire stack after a change that follows an undo.

Screenshots
Environment Information

  • NodeJS v16, building this repository from source
  • Yjs version 13.5.29
@andrewheumann andrewheumann added the bug Something isn't working label Mar 29, 2023
@andrewheumann
Copy link
Author

Also worth noting that if I swap out the YMultiDocUndoManager for a Y.UndoManager in the test, it passes.

@andrewheumann
Copy link
Author

FWIW this change seems to cause the test to pass, but I confess I'm groping around in the dark a bit here, not sure it's a valid solution:

image

@dmonad dmonad closed this as completed in fcd82d6 Mar 31, 2023
@andrewheumann
Copy link
Author

Thank you for fixing this so quickly! much appreciated!

@dmonad
Copy link
Member

dmonad commented Apr 2, 2023

Sure thing. Thanks for the test case and the correct fix! I incorporated both in the fix :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants