This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Repository navigation
Implement a new editor view with React.js - #1863
Merged
Merged
Conversation
Contributor
Author
There was a problem hiding this comment.
It was added when I installed React. I don't really know why. I will try removing it and seeing if anything breaks.
added 27 commits
April 17, 2014 16:52
The space-pen view is now a simple wrapper around the entire React component to integrate it cleanly into our existing system. React components can't adopt existing DOM nodes, otherwise I would just have the react component take over the entire view instead of wrapping.
Might as well go with the flow
The overlayer is absolutely positioned to exactly fill the scroll-view. If we can retain this strategy and never give the input a position that exceeds the bounds of the overlayer, we can guarantee that it never forces the scroll position of the scroll view to change when it is focused due to the browsers default behavior.
This bakes character width tracking into display buffer directly, which moves us toward a world where all rendering decisions can be made in the model to strictly control DOM reads.
Whenever new lines are added to the screen, we measure and store any unseen scope/character combinations in the DisplayBuffer.
Scroll positions, height, width, line height. We force update when one of these observed properties changes.
added 19 commits
April 17, 2014 16:52
We accumulate pending changes and pass them to the lines and the gutter to help them determine whether to update. The lines only update if the visible row range changed or if there was a change in the visible row range.
This ensures we don't perform two updates of the cursors component when cursors move as part of a larger change, such as typing text.
It creates a simpler DOM structure.
When the target of a mousewheel event is removed, it breaks velocity scrolling. Previously, we were preserving the entire screen range when scrolling with the mouse wheel, which caused a lot of DOM nodes to accumulate. Now we only preserve the individual line and line number associated with the target of the mousewheel event, moving them just off screen below all the on-screen lines and line numbers. This keeps the number of DOM nodes limited while retaining velocity effects.
It impacts scrolling performance. We can measure when scrolling comes to a halt.
Emitting the event *before* update, rather than after. This is because we read from the DOM after update to measure new characters, which forces layout, so emitting the event after measuring forces another layout when the position is updated.
Contributor
Author
|
Okay, there's a bit more to do but I'm going to merge this so we can start dogfooding it. Check "Use React Editor" in your config to try it out. |
Contributor
Author
|
Okay, I regretted merging this and force pushed it back. It's not ready to be tested yet. Lots of minor but frustrating issues are preventing it from really being usable. |
6 tasks done
34 of 35 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR is about making it easier to optimize the editor view and harder to introduce changes that de-optimize it.
Problems with the existing editor
Experience building the original editor view taught us that avoiding extra reflows is essential to good performance. We can optimize the shit out of our JS, but if we read from the DOM after touching it, performance is going to suck. If we want to be fast. It's critical that we batch all reads and writes in a reflow-minimizing way, and the less we access the DOM the better. The DOM needs to be treated with kid gloves.
Another hurdle in optimization is the complexity of the original editor implementation. To minimize DOM updates, we had a headache-inducing region invalidation routine. Combine that with lots of ad-hoc DOM updates for various aspects of the view that have evolved over time, and it's pretty difficult to reason about the behavior of the editor.
The editor is one of Atom's most essential components. It needs to be as fast as possible, and we can't afford to get mired in complexity every time we work on it.
How React.js helps
The core idea behind React is that you express the state of the DOM at a given point of time declaratively, allowing React to compute a minimal set of DOM updates based on a diff with the previous state. This is great, because one source of confusion in the old editor is the sequence of actions that update the DOM. Now that's all abstracted away. React makes DOM programming similar to traditional server-side web programming, where you get to assume a page refresh in between view states.
Rewriting the editor view was also an opportunity to make other improvements, which were easier thanks to the simplicity afforded by starting with a clean slate and using a superior tool:
Deployment plan
Changing editor rendering is a pretty huge deal and there are bound to be issues. This editor view has a superior design for the future, but the existing editor view has been battle tested and is stable. We need feedback about the new editor without forcing people to use it, so my plan is to initially deploy it behind a feature flag. The new editor will only be used if
core.useReactEditoris true.Steps: