josephg / diamond-types

The world's fastest CRDT. WIP.
1.61k stars 31 forks source link

Undo/Redo support #3

Open s-panferov opened 3 years ago

s-panferov commented 3 years ago

Hi, thanks for the amazing library. I have a quick question: can undo/redo be implemented on top of this library and what is a general strategy of doing so?

josephg commented 3 years ago

Good question!

Its still a bit early for me to add direct undo/redo support. Probably the simplest way to implement it is to have an undo stack, and simply make a change which does the inverse of the user's action.

There's an API internally (which I should expose) for getting a unique ID based on a document position, or an ID (or sequence of IDs) for some inserts.

So for undo, it would be something like:

Ideally we'll have some utility code for this inside diamond types, but I'm working on file loading & saving and some other features added first.

josephg commented 2 years ago

Its probably time to adding undo / redo support now. The API surface area internally is ready for it, and I want it for the wiki.