I am working on a collaborative drawing application and am using Yjs as the backbone for state synchronization. Btw it is a great lib and I’m really grateful that is exists!
I use XML elements to store the shapes, each element has a few properties like position, rotation, scale etc. Based on this info I draw them to the canvas.
Now I am trying to add a distributed undo/redo support and I the built-in UndoManager seems to be a good fit. It works fantastic except for one use case:
- User A creates a shape S
- User B rotates S
- User A undoes (removes the shape)
- User A redoes (adds the shape back)
In this case I’d expect to get the rotated shape back, but it seems the redo puts the non-rotated version back.
As far as I understand to resolve this issue I have to update the redo log whenever there is an undo and update the undo log when there is a redo (based on this: How Figma’s multiplayer technology works?
I can see that there are two hook points for the UndoManager: stack-item-added/stack-item-popped, but unfortunately I am stuck. I don’t know how to modify the stack and so on.
So my question is what approach should I follow here? How can I modify the undo/redo log elements if it is even possible?