editor: Refactor scrollbar-related code (#24134)

This PR is primarily an implementation of @osiewicz
[comment](https://github.com/zed-industries/zed/pull/19495#pullrequestreview-2488877957)
in an effort to increase maintainability after the horizontal editor
scrollbar was added in #19495 . I also want to build on these changes in
future PRs to adress some other small bugs.

This primarily does the following:
1. Uses `along` wherever possible
2. Fixes the amount of mouse event listeners attached to the editor when
scrollbars are displayed to 2 instead of 2-4 in case both scrollbars are
displayed.

This can be done since only one scrollbar can be dragged by the cursor
at any given time, so the event listeners now account for that. The
state reflecting the scrollbar dragging state was also updated
accordingly.

It does not change any functionality besides the aforementioned event
listener code as well as some minor bugs which where present after
#19495 , namely:
- One missing `cx.stop_propagation()` (see
[here](a8741dc310/crates/editor/src/element.rs (L4684))
and
[here](a8741dc310/crates/editor/src/element.rs (L4838))
respectively).
- The horizontal scrollbar thumb having a small border on the left side,
which seems to be unintended for the horizontal scrollbar whilst
intended for the vertical one. Since this is a minimal change, I figured
it could be already included in this PR.

This PR admittetly grew quite large over time, however, much of the diff
is just renames to account for the code now working for both axes as
well as moved code. The logic remains (or should at least be)
unaffected. If I should split this into two PRs or remove some of the
changes, please let me know.

Release Notes:

- N/A
This commit is contained in:
Finn Evers 2025-03-25 22:08:46 +01:00 committed by GitHub
parent 1574a3a2fd
commit a65ea2708c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 394 additions and 563 deletions

View file

@ -1576,7 +1576,7 @@ impl Editor {
this._subscriptions.extend(project_subscriptions);
this.end_selection(window, cx);
this.scroll_manager.show_scrollbar(window, cx);
this.scroll_manager.show_scrollbars(window, cx);
jsx_tag_auto_close::refresh_enabled_in_any_buffer(&mut this, &buffer, cx);
if mode == EditorMode::Full {