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

Could we have an undoCompose function? For calculating the reverse of a delta when composed with a base delta. #28

Closed
jaredly opened this issue Sep 14, 2018 · 7 comments

Comments

@jaredly
Copy link

jaredly commented Sep 14, 2018

E.g. this would make undo simpler / faster.

The quilljs history module has a guessUndoDelta, which can only guess the undo of an insert, understandably -- you need the base delta to be able to calculate the undo of a delete, for example.

So I'm envisioning a delta.undoCompose(baseDelta) such that the following holds true for any delta:

const undo = delta.undoCompose(baseDelta);
deepEqual(baseDelta.compose(delta).compose(undo), baseDelta)
@jhchen
Copy link
Member

jhchen commented Sep 15, 2018

Quill's clipboard module deliberately does not want to store all baseDeltas (which would be the entire document). Also its clipboard deals with insert-only deltas which can use diff() if one is willing to store all baseDeltas. Are there other use cases you have in mind?

@jaredly
Copy link
Author

jaredly commented Sep 15, 2018

Right, you wouldn't be storing the baseDeltas. I'm envisioning this as a better way to do diff() that is aware of what the delta was that is making the change.
So instead of

const undoDelta = baseDelta.compose(delta).diff(baseDelta);

you can do

const undoDelta = delta.undoCompose(baseDelta)

@jhchen
Copy link
Member

jhchen commented Sep 17, 2018

I see what you mean now. baseDelta needs to be an insert-only delta I believe but delta can be an arbitrary delta in your examples. I can see its use for undo and could replace guessUndoDelta. Are there other use cases though? If not it should arguably belong in Quill instead of here. Either way is this something you'd be willing to contribute a PR to?

@jaredly
Copy link
Author

jaredly commented Sep 19, 2018

Yup, I'd definitely be willing to contribute a PR. I'd much rather have it live here, because quill is tied to the dom, and this undoCompose would be data-only

@jhchen
Copy link
Member

jhchen commented Sep 20, 2018

Great thanks! Let me know when there is something to look at or if you have questions getting started.

@jhchen
Copy link
Member

jhchen commented Jan 29, 2019

Hey is this something you are still planning on working on? We were planning on adding this soon if not.

@jaredly
Copy link
Author

jaredly commented Jan 29, 2019

I haven't gotten to this yet, it's a little farther down on my priority list

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