Can partly parse and update the ast when content change?


#1

Suppose user change some content by copy paste or keyboard input, can I assume this will only affect some blocks near the cursor.

Try to read the spec, but still confused.

Parse the whole file each time seems not so efficient.


#2

Pasting content in can affect any part of the rest of the tree. For example, inserting ``` at the top of a document can change the entire rest of the document.

Inserting [1]: http;//example.com at the bottom can change links throughout the document.

So in that regard

can I assume this will only affect some blocks near the cursor.

No, absolutely not.


With that said, you can parse the changed content first to determine whether the content being added requires a complete refresh. For example, if what’s being pasted in is just alphanumeric and the spaces are determined to be “safe” (i.e. no new indentation).