Skip to content

scrollbar: Only drag or jump the track on the primary button - #4038

Merged
madcodelife merged 1 commit into
longbridge:mainfrom
costajohnt:fix/scrollbar-left-button-only
Nov 18, 2026
Merged

madcodelife merged 1 commit into
longbridge:mainfrom
costajohnt:fix/scrollbar-left-button-only

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Closes #4036

Description

Scrollbar::paint didn't check event.button, so a right or middle press on the thumb started a drag and a press on the track jumped it, and the press was stopped there. A non-left release also ended an ongoing left drag.

Both the mouse-down and mouse-up handlers now only act on MouseButton::Left, as the issue suggested. The drag move handler already only acts while the left button is held (event.dragging()), and hover tracking stays button-agnostic. Since the scrollbar no longer stops a right or middle press, it reaches the content underneath, so an app's right-click menu can open over the scrollbar.

The component and shell scroll wrappers use the base Scrollbar, so they pick this up too. slider, resize_handle and carousel/scroll_mask already check for the left button.

How to Test

  • New test only_the_primary_button_drags_or_jumps in crates/base/src/scrollbar.rs (uses the existing harness): right and middle down/up on the thumb and on the track don't start a drag or move the offset, and a right release during a left drag doesn't end it. It fails with either check removed.
  • cargo test -p gpui-base (1769 lib tests plus the other targets), cargo clippy -p gpui-base --all-targets -- -D warnings, rustfmt --check on the file, typos.
  • Tested on macOS. I didn't click through the story app by hand; the test drives real mouse events through gpui's dispatch with the real Scrollbar.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

The fix and test in this PR were written with AI assistance (Claude) and reviewed against the project's style.

A right or middle press on a scrollbar started a thumb drag or jumped the
track, and a non-primary release ended an ongoing primary drag. Check
event.button in the mouse-down and mouse-up handlers.

Closes #4036
@huacnlee

Copy link
Copy Markdown
Member

✅ Correct, minimal fix; scrollbar press and release now only react to the primary button.

Reviewed head 077908b.

  • Both the mouse-down handler (thumb drag and track jump) and the mouse-up handler now check MouseButton::Left. Drag-move was already gated by event.dragging(). Because a non-primary press is no longer stopped, it now reaches the content underneath, so context menus over the scrollbar work. That matches native platform behaviour, and there is no public API change.
  • The new test only_the_primary_button_drags_or_jumps passes and covers both the thumb and the track, plus a secondary release during a primary drag.

Ran

  • cargo test -p gpui-base --all-features scrollbar: 46 passed, 1 failed (repeated_touch_and_mouse_drags_keep_the_painted_grab_point). That test also fails at this PR's merge base without the change, so the failure was already there and this PR doesn't cause it.
  • cargo clippy -p gpui-base --all-targets -- -D warnings: clean.
  • CI hasn't run on this PR yet.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@madcodelife
madcodelife merged commit 837ae57 into longbridge:main Nov 18, 2026
18 of 19 checks passed
@madcodelife

Copy link
Copy Markdown
Member

Thank you!

@costajohnt

Copy link
Copy Markdown
Contributor Author

Thanks for merging!

linruohan pushed a commit to linruohan/gpui-kit that referenced this pull request Nov 20, 2026
…dge#4038)

Closes longbridge#4036

## Description

`Scrollbar::paint` didn't check `event.button`, so a right or middle
press on the thumb started a drag and a press on the track jumped it,
and the press was stopped there. A non-left release also ended an
ongoing left drag.

Both the mouse-down and mouse-up handlers now only act on
`MouseButton::Left`, as the issue suggested. The drag move handler
already only acts while the left button is held (`event.dragging()`),
and hover tracking stays button-agnostic. Since the scrollbar no longer
stops a right or middle press, it reaches the content underneath, so an
app's right-click menu can open over the scrollbar.

The component and shell scroll wrappers use the base `Scrollbar`, so
they pick this up too. `slider`, `resize_handle` and
`carousel/scroll_mask` already check for the left button.

## How to Test

- New test `only_the_primary_button_drags_or_jumps` in
`crates/base/src/scrollbar.rs` (uses the existing harness): right and
middle down/up on the thumb and on the track don't start a drag or move
the offset, and a right release during a left drag doesn't end it. It
fails with either check removed.
- `cargo test -p gpui-base` (1769 lib tests plus the other targets),
`cargo clippy -p gpui-base --all-targets -- -D warnings`, `rustfmt
--check` on the file, `typos`.
- Tested on macOS. I didn't click through the story app by hand; the
test drives real mouse events through gpui's dispatch with the real
`Scrollbar`.

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [ ] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

The fix and test in this PR were written with AI assistance (Claude) and
reviewed against the project's style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scrollbar: right-click starts a thumb drag / track jump

3 participants