Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix shaking editor when typing #16886
Description of the Change
When using DPI scaling the scroll position could be set to a position that was not possible causing a scroll event to scroll back. This was causing the editor to shake when editing. This PR fixes this by rounding scrollTop and scrollLeft to a physical pixel instead of rounding using Math.round
Why Should This Be In Core?
It is already in Core
Looks good, nice work reproducing this @Ben3eeE!
To recap, we were setting the scroll position to a position that was not physically addressable due to
window.devicePixelRatio being a number between 1 and 2. As such, the browser clipped the requested scroll position, which in turn triggered a new scroll top change to a position that was actually addressable. This new event was intercepted by
TextEditorComponent which attempted to scroll again, but rounding differently this time around due to the clipping the browser was applying.
By always rounding the scroll top position to a physically addressable pixel we solve this problem and prevent the browser from doing the clipping itself, thereby avoiding the flickering as well.