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

feature request: add arbitrary events to the undo history #800

Open
alidcast opened this issue May 20, 2018 · 3 comments
Open

feature request: add arbitrary events to the undo history #800

alidcast opened this issue May 20, 2018 · 3 comments

Comments

@alidcast
Copy link

alidcast commented May 20, 2018

Following discussion in forum about being able to undo decoration deletions: https://discuss.prosemirror.net/t/add-inverse-of-decoration-step-to-history/1342/3

One idea for the API, is that, similar to how you can add an onRemove option to mapped decorations, you can add an onUndo option to the meta transaction. E.g. tr.setMeta(key, value, { onUndo: Function(tr) }) and let the user handle the logic for restoring a specific decoration based on the previous transaction.

I feel like that's a pretty simple way of handling this. But I'm not sure if there's any nuances I'm not taking into account, so opening this issue to start a discussion and see if we can land this feature. :)

@alidcast
Copy link
Author

alidcast commented May 20, 2018

I'll add a quick example of how'd it look using above API

const commentToDelete = {..}
dispatch(
  tr.setMeta(commentPlugin, { type: 'deleteComment' comment: CommentToDelete }, { 
    // option1 append steps to undo transaction
    appendUndo (tr) {
        return tr.setMeta(commentPlugin, { type: 'createComment', comment: commentToDelete }
    }
    // option 2 dispatch new transaction based on new state after undo
    // onUndo (state, dispatch) { ... }
  })
)

@vladminsky
Copy link

@alidcastano, is there any updates or suggested workarounds on this issue?

@marijnh
Copy link
Member

marijnh commented May 23, 2019

See ProseMirror/rfcs#12

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

3 participants