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/Redo support #3

Open
s-panferov opened this issue Sep 18, 2021 · 2 comments
Open

Undo/Redo support #3

s-panferov opened this issue Sep 18, 2021 · 2 comments

Comments

@s-panferov
Copy link

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
Copy link
Owner

josephg commented Sep 28, 2021

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:

  • When inserting new content:
    1. Insert actual items
    2. Get IDs for inserted elements
    3. Push Delete(ids) to undo stack
  • When deleting:
    1. Delete items
    2. Get ID for cursor position where items were deleted
    3. Push Insert(cursor, deleted_content) to undo stack

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 josephg changed the title Question: Undo/Redo Undo/Redo support Mar 28, 2022
@josephg
Copy link
Owner

josephg commented Mar 28, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants