WIP: introduce unscaled measurements for consistent gaps in a scaled editor #73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-scaled-gaps"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR hopes to resolve the issue mentioned in this discussion, where the editorview gaps are inconsistent as the editor is being scaled (only noticeable if scrolled down far enough).
I found that the problem was in the implementation of the
DocView.computeBlockGapDecowhere the "screen"-space coordinates divided by the scaleY were used to calculate the height of the gap.To solve this issue, I introduced originalLineHeight, originalCharWidth, originalTop, originalHeight, etc. in the HeightOracle and HeightMaps, which are the unscaled sizes and coordinates of the lines (instead of the screen coordinates). These are then used to calculate the height of the gaps. This approach avoids floating-point errors that could occur when adding up the heights of the lines (which was causing the visual bug before), as it now sums the unscaled heights of each line instead.
There might be some bugs as this is still a work in progress.
I'm not convinced the tracking of original sizes is a good idea. These values are used for estimating, and the tiny errors produced by multiplying then re-dividing seem unlikely to be much of an issue. And the extra, noisy code needed to track them is a serious cost.
I agree that it does introduce a bunch of noisy code. However, it did resolve the issue I was having. I couldn't find another source for the scaling issue, if you have any other ideas or hints about where the issue might be coming from, I’d love to investigate further! But I'm not really sure where else I should be looking in the codebase.
Upon further investigation I've found that the values returned by
.getBoundingClientRect().heightare slightly inaccurate, which causes an increasing error when we sum a bunch of these heights together to get the measured gap height. Here are some logs that show the errors:As you can see it is often off by ~0.004 pixels, which will be noticeable in scenarios with hundreds or thousands of lines of code.
So, instead of using the previous approach of mine where we keep track of all the original coordinates, it might be more interesting to calculate an accurate lineHeight using the originalHeight:
This would replace all the noisy code I've previously written (the originalLineHeight etc. can be removed everywhere as we now have an accurate lineHeight to calculate the gap height).
Do you think this would be a better solution? If so, I can make a new pull request.
Again, there is no expectation for the estimated height of unrendered lines to be 100% correct. 0.004 pixels per line would be 40 pixels per 10 000 lines, which is not huge, and will also definitely occur in non-scaled scenarios when a couple of wrapped lines are estimated incorrectly or there's some styling going on.
The text staying in the precise same place when you scale the editor is not a level of accuracy I'm aiming for with this implementation. You may be able to implement something like that with careful custom code, but viewporting is complicated enough with estimated heights.
Alright, fair enough, if this is not something codemirror is aiming for I will close this PR. Thanks for your time!
Pull request closed