Specification for serialised changset?

I’m currently sending only the serialised changes to the server using something along the lines of:

EditorView.updateListener.of((e) => send("update", e.changes.toJSON()))

And I need to implement the application on the server (not js/ts, elixir). But I couldn’t find documentation for the format. The common [insertion, [removal, new_string]] is sorta obvious, but when observing while typing, others came about, like [0, [0, "", ""]] (or similar).

The tests use a format like over("2 2:2 2", "0:2 6", "4 2:2 2") and I’m not quite sure how they relate to one another.

There’s no specification for these, but they won’t change, because that would break things for people. The elements in the array represent sections of the old document. Plain numbers are unchanged ranges. Arrays are replacements, where the number at the start of the array is the amount of deleted text, and the strings following that is the inserted text, split by line. So [0, "", ""] inserts a line break, [1] deletes a character, etc.

Thanks for the clarification!

I’ve got a bunch of cases working easily already, but was wondering:

iex> Codemirror.apply_changes("Some content", [5, [0, "new "], 7])
"Some new content"

What function does the 7 serve? Sometimes it’s there, sometimes it’s not.

Also, the docs say that a ChangeSet represents a group of modifications, but I haven’t gotten more than a single modification from EditorView.updateListener. Is that coincidence, design or is [5, [0, "new "], 7] simply already considered a group? If not, what would a group look like?

If I were to write a specification for this, what format would you prefer if any? BNF? Unless it’d be wasted efforts of course. :slight_smile:

[5, [0, "new "], 7] is a change that, inserts “new” at position 5 in a length-12 document. “skip 5, replace 0 with the string ‘new’, skip 7”. If the change is at the very end of the document, the skip at the end will not be there.

While most editing changes will, obviously, make only a single modification to the document. it’s not hard to create a transaction that makes several changes.

I don’t think there’s a need for you to write a specification for this.

All right! Works great now! Thanks.