Mapping Deletions in ChangeSets

Hello,
I have a use case where I’m maintaining two versions of a document that is being edited with CodeMirror. To do this, I have created a translation layer using ChangeSets. Generally this is working great, except when the specific translated text is deleted.

Let’s call the two versions of the document A and B. The user only interacts directly with A.

A starts off like this:

Hello

![[image.jpg]]

world

The translation layer is the ChangeSet named AToBChanges which will transform the document into this:

Hello

![[changed]]

world

Now, if the user deletes the entire line containing the image, the resulting A document is like this:

Hello

world

and CodeMirror gives us the expected update.changes reflecting that change.

In order to update document B, I am calling update.changes.map(AToBChanges), and expect that the result would be a ChangeSet that deletes ![[changed]]\n, however the result is a ChangeSet which deletes ![[ and ]]\n.

This is unexpected. Why is it removing only the characters which were not changed by AToBChanges? Could you point me towards what I should be calling instead please?

Thank you!

I have created a minimal reproduction of the issue in the CodeMirror playground here. Hopefully that can help demonstrate my problem :slight_smile:

What ChangeSet.map does is transform the given change set (this) so that it can apply to the document produced by the argument change set, as if both changes happened concurrently. Because aToBChanges inserts content, and inserted content is never cancelled because of concurrent changes, this approach will not get rid of it.

Thus, I don’t think ChangeSet.map is going to cover what you’re trying to do here.

Do you happen to know if there’s another tool in the CodeMirror ecosystem that would work for this scenario?

Thank you

Not really, I think. Sounds like you want another style of OT than what ChangeSet.map implements.