Hello!
I’m working on a math editor with extended markdown syntax.
Among others, I’ve implemented widget decorations for math in display mode (that render the math as you type it).
As the math code in display mode can span multiple lines, these decorations are provided through a state field; however, unlike the underline example provided in the docs, my decorations are determined by syntax (similar to markdown code blocks, except with $$ delimiters instead of ```).
Currently, I achieve this by iterating the entire syntax tree on every update, throwing the old widgets and recomputing the new widgets by their positions.
Of course, this feels wasteful. But more than that, on long documents - seems to happen over the 3000 character mark - this also seems to create a flickering effect, which I’m assuming is caused by the parser splitting the work into multiple chunks on large documents (I remember having read this on some discussion here, but could not find it).
Not sure if it’s relevant, but this is what the flickering looks like:
And here I edit text around the 3000 character threshold:
I’ve also thought of implementing refined diff logic between old & new decorations on every update (by looking at the changed areas rather than recomputing the decorations from scratch) but couldn’t really make it work, perhaps because I’m not familiar enough with CodeMirror.
Then, what’s the best approach for implementing such syntax based, line break replacing decorations?
As always, thanks a lot for your time and effort, and for making CodeMirror!