-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: implement rendering through HTML elements #35
Comments
I implemented NyaoVim with React.js and DOM at first. However, it causes big performance problem (e.g. scrolling screen causes entire re-rendering). I know that Atom and VS Code (monaco editor) use DOM for editor surface. Atom did so many rendering optimizations to improve performance but I don't have such a skill. Additionally, rendering events from Neovim don't get along with DOM. Rendering events assumes to render an editor on 2D screen. For example, So I introduced Anyway, you can try using DOM. I guess adding new screen renderer in addition to |
I indeed ran with the same exact problem with React, scrolling was a real issue. I found that replacing the whole React thing with a custom DOM manipulation interface much more efficient. For both problems, I found implementing a LineModel helped a lot (see https://gist.github.com/romgrk/7b155dcc273d46f125c22fe5de2b2c4f). const renderToken = token => `<span style=${token.attr}>${token.text}</span>`;
const lineHTML = tokens.reduce((accumulator, current) => accumulator += renderToken(current), ""); Also, it means that we could also have an actual model of what's on the screen, which isn't possible with a canvas. This allows to not re-render the whole line but just the elements that have changed. (Much like React's VirtualDOM). It also means that we do not need to display the elements immediately when the neovim event comes in, and throttle them. (I found 5ms to be a correct latency) I did implement a POC replacement for On the scrolling issue, again the models handles the uggly cases by providing an |
I was thinking about this, too, and I came to the realisation that a |
Hi there :)
I was wondering if you would consider switching the rendering implementation to HTML elements rather than a canvas?
I think this would be better because if there is one thing that browsers are optimized for, it's text rendering. Using a canvas does give good results but is still not as performant as what the browser can do (IMO), e.g. font aliasing (turning on
optmizeLegibility
in CSS)Besides that, it also gives a whole lot more possibilities for future widgets, where one could use the full HTML specs (mouse hover events, etc.) to build on top of this.
If it can convince you, I did a prototype (it was for testing the external popup for neovim) which gives pretty good results: https://www.youtube.com/watch?v=TI5azVeDUDo
The text was updated successfully, but these errors were encountered: