zed icon indicating copy to clipboard operation
zed copied to clipboard

Fix scroll thumb

Open alygin opened this issue 1 year ago • 3 comments

Editor scrollbar has several issues that show up on large files:

  • The thumb scrolls beyond the window.
  • When dragged, the thumb goes out of sync with the mouse pointer.
  • When the scrollbar trunk is clicked, the thumb jumps incorrectly.

https://github.com/zed-industries/zed/assets/2101250/320dba59-a526-4e68-99b3-1186271ba839

The reason is that the scrollbar now has two modes:

  1. The "basic mode" for small files, when the thumb height correctly represents the visible area, i.e. the top of the thumb matches the top visible row (let's call it top-to-top sync), and the bottom of the thumb matches the bottom visible row.
  2. The "extended mode" for large files, when thumb becomes too small and we have to impose minimal height to it. In this mode we have a vertical offset of the first row position inside the scrollbar, we try to position the thumb center-to-center with the editor.

...and the second mode is not implemented correctly. Also, mouse event handlers ignore it. It is possible to fix this implementation, but I'm not sure if it worth doing because it a) leads to some confusing cases (for instance, in the extended mode the first row marker is not at the top of the scrollbar), and b) differs from what all other editors do.

Here's a previous mentioning of this problem: https://github.com/zed-industries/zed/pull/9080#pullrequestreview-1927465293

This PR changes the "extended mode", making it synchronize the thumb top-to-top with the editor. It solves all the mentioned problems and makes the scroll thumb work the same whay as in other editors.

But if you want to stick to the idea of the center-to-center sync for large files, I can do that too.

Release Notes:

  • Fixed scroll thumb behaviour.

Optionally, include screenshots / media showcasing your addition that can be included in the release notes.

  • N/A

alygin avatar Apr 17 '24 06:04 alygin

the consistency and precision of the current "top of the thumb to clicked place" approach is much better than before

Actually, when the user clicks the scrollbar, the approach is to scroll the "clicked row" to the center of the editor, which means the top of the thumb may be above the clicked place. But in large files, like project.rs, where one scrollbar pixel represents many editor rows, it's hard to notice. On relatively small files this centering is easily visible.

I was never able to click top-to-bottom without the jumps.

Hm, that's interesting. I cannot reproduce it. Hundreds of clicks and not a single case of incorrect thumb positioning.

Do I understand correctly that if ther're no search results, everything works?

alygin avatar Apr 18 '24 18:04 alygin

I found how to reproduce it. It has nothing to do with search results or any markers at all. It's also present in the stable version.

The problem occurs when the clicks also involve little draging. It makes MouseMoveEvent fire, and the calculation of the delta between mouse positions uses the wrong starting point.

I guess I'll add the fix of this problem to this PR.

alygin avatar Apr 18 '24 19:04 alygin

@SomeoneToIgnore , fixed

alygin avatar Apr 18 '24 21:04 alygin

I see the problem, but I don't know a good soluton either. It looks like all the editors use the same approach (the one implemented in this PR).

to shift the thumb a bit more during the scrolling only.

What kind of shifting do you mean?

I was thinking of highlighting the part of the thumb that really represents the visible area while scrolling (and maybe muting the other part of the thumb a bit), so the user could aim better:

изображение

But it has its limitations too. In project.rs the highlighted part will be only two or three pixels high on my laptop.

alygin avatar Apr 19 '24 17:04 alygin