Migrate the code editor to CodeMirror #2444
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CodeMirror is an extensible, modular, and lightweight (everything is opt-in by default). When we started Livebook it was in the process of rewriting, but things stabilised since then and I decided to migrate from Monaco. Monaco is fairly heavy and even with cherry-picking imports, it's just a lot of stuff that we don't need. Over time we accumulated a lot of workarounds, including monkey-patching.
A couple updates worth noting:
Full load for the session page content 6.9 MB -> 4.0 MB (actual transfer 1.6 MB -> 958 kB).
Editor history distinguishes remote changes, so when collaborating, undo rolls back local changes only (properly transformed).
I revisited collaborative cursors propagation and now they are a part of the Operational Transform, meaning that the cursors update in sync with changes, which is particularly relevant under noticeable latency.
I made all editor mounting lazy. We mount the editor only once it enters the viewport. We put the editor content into the page though, so search works and the scroll position is accurate. This way, even very large notebooks can be opened pretty quick.
CodeMirror uses an incremental parsing system for highlighting and indentation, we now have livebook-dev/codemirror-lang-elixir.
Closes Can't create cell on Safari when a previous cell is focused #2003, closes Keyword and Map not highlighting properly #2417. Actually fixes do/end autocompletion puts cursor in the wrong line #152 and Livebook crashing attempting to open a livebook. #1098.