automerge / automerge-classic

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
http://automerge.org/
MIT License
14.76k stars 467 forks source link

Fix insertion position of operations on root object #447

Closed ept closed 2 years ago

ept commented 2 years ago

This PR fixes a bug reported by taronish (via Slack). If a document contained a text object with enough operations to split it across two blocks, and then a root object operation was performed with a higher key than any existing key on the root object, then that operation would be inserted at the beginning of the second block, not after the existing root object operations as it should. Further down the line this would cause exceptions like "RangeError: could not find list element with ID" or "RangeError: no matching operation for pred" even though the operations were valid.

I fixed it by correcting the block skipping logic in seekToOp. Incidentally, the fix was closely related to a simplification of the block metadata that I wanted to do anyway, so I did that simplification at the same time.