-
-
Notifications
You must be signed in to change notification settings - Fork 433
Description
I recently came across this project https://github.com/satya164/react-simple-code-editor .
That library works by allowing users to edit inside a native textarea
, while overlaying syntax-highlighted code on top of it. On the face of it this seems like quite an elegant and simple approach that works well.
I find myself wondering what makes the more complex approach taken by CodeMirror superior to that approach, which seems so simple by comparison.
I can only think of the following drawbacks to the approach taken by react-simple-code-editor
:
- Syntax highlight requires a complete parse on each keystroke. This could be addressed by using
tree-sitter
orlezer
for maintaing the AST. - The syntax-highlighted DOM tree is clobbered and regenerated on each keystroke. This could be addressed by using virtual DOM to update the DOM based on the fresh AST (e.g. using
preact
orreact
). - Really large files would render in full with this approach, whereas CodeMirror only renders what's visible.
The above problems can be ignored for use cases where the files will not be large, or syntax highlighting is not required when the amount of text is above a certain threshold.
I'm posting this issue as a sanity check, to see if I'm missing some important points that make the complex update patterns within CodeMirror inherently a better choice than the approach taken by react-simple-code-editor
. There probably are many, but I fail to see them at the moment.