CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
504 stars 74 forks source link

🐞 Scrollbar twitches around when scrolling large file #184

Closed Eliulm closed 8 months ago

Eliulm commented 1 year ago

Description

When scrolling large files, the scrollbar twitches around the place. Only if the whole document has been completely viewed, the scrollbar will behave as expected.

Upon further investigation, I found that the textview.frame.height property changes a lot during scrolling. It might be the reason, why the scrollbar behaves weirdly.

To Reproduce

  1. Open file with content that does not fit in viewport.
  2. Scroll

Expected Behavior

Scrollbar animation should be smooth and self.textView.frame.height should stay constant during scrolling.

Version Information

CodeEditTextView: 0.6.2 macOS: 13.3.1 Xcode: 14.3

Additional Context

No response

Screenshots

https://user-images.githubusercontent.com/82230675/235370078-81c50a53-5c0f-48c3-9ca0-aa4aeaa3b433.mov

austincondiff commented 1 year ago

Not sure if this is related or not, but when the scroll reaches line 100, things shift to the right to account for the additional digit. We should account for maximum ruler width upon file open, not on scroll.

It seems like we do this for wrapped lines as well. My theory is that we assume all lines do not wrap. When we scroll to wrapped lines, this adds additional height to the overall scroll height and will adjust the scroll indicator to account for this additional height (again this is just a theory).

After watching your video, it seems like the indicator gets bigger then smaller then bigger then smaller, etc. I believe this is because the wrapped lines are scrolling out of view so it is again assumed that they will be the unwrapped height.

Edit: I can validate this theory by scrolling an wide window with no wrapped lines and a narrower window with wrapped lines.

Large window with no wrapped lines:

https://user-images.githubusercontent.com/806104/235371836-f7a3d525-f9b3-46b0-a8f7-f7feb3fba536.mp4

Smaller window with wrapped lines:

https://user-images.githubusercontent.com/806104/235371865-4181b5f8-cbbb-46f7-a29f-25160f0d0705.mp4

Notice the scroll indicator in the larger window with no wrapped lines remains consistently sized as I scroll down the page while the scroll indicator in the smaller window with wrapped lines does not.

Eliulm commented 1 year ago

Interesting. However, I just tried this too, but I still get the twitching in a file without line wraps:

https://user-images.githubusercontent.com/82230675/235373888-cb418bd6-951b-4f8c-91d9-14b008e3cbe3.mov

thecoolwinter commented 1 year ago

There's two issues happening here:

austincondiff commented 1 year ago

@thecoolwinter That makes a lot more sense. Well if it is any indication, when there is not enough text to fill the viewport, the view is vertically scrollable, the height is the viewport height plus the CodeEdit status bar height (which I want to say is a bottom edge inset. So maybe we are not taking edge insets into account?