Hello and thanks for creating this lovely tool!
I am writing a music live coding editor where decoration changes can be dispatched every frame.
When the document gets shorter, it can happen that changes are fired that still receive the old document state, leading to errors like:
Position 281 is out of range for changeset of length 180
When that error happens, the application crashes and gets into an unusable state. It would be really helpful to be able to catch that error and just ignore it, because it is not critical if a highlight is missed.
I created a minimal reproduction here: react-codemirror-range-error - CodeSandbox the error will be thrown whenever the document content is deleted all at once.
I assume the problem is that the document changes between the call to view.dispatch and the actual execution, possibly because requestAnimationFrame is not fired synchronously.
- Is there a way to hook into codemirrors requestAnimationFrame loop or a way to always get the latest state of the document?
- If this is a just a problem with the react component, wouldn’t it still make sense to be able to catch critical errors?