Skip to content

terminal: Fix mouse scroll report count for negative scroll lines#49931

Merged
MrSubidubi merged 1 commit intozed-industries:mainfrom
emamulandalib:fix-terminal-mouse-scroll-down
Feb 24, 2026
Merged

terminal: Fix mouse scroll report count for negative scroll lines#49931
MrSubidubi merged 1 commit intozed-industries:mainfrom
emamulandalib:fix-terminal-mouse-scroll-down

Conversation

@emamulandalib
Copy link
Contributor

Follow-up to #45600.

Summary

Fix mouse scroll reports sending only one event when scrolling down in terminal apps with mouse mode (tmux, neovim, etc.), regardless of how many lines were scrolled.

The Problem

After #45600, trackpad scrolling speed was fixed. But when scrolling down (negative scroll_lines), the terminal was still sending only one scroll report per gesture, no matter how many lines the user scrolled. Scrolling up worked correctly.

Root Cause

In scroll_report() we had:

.map(|report| repeat(report).take(max(scroll_lines, 1) as usize))

scroll_lines can be negative (scroll down) or positive (scroll up). For negative values:

scroll_lines max(scroll_lines, 1) Reports sent Verdict
3 (up) 3 3 Right
-3 (down) 1 1 WRONG

So we always sent exactly 1 report when scrolling down, losing the scroll magnitude.

Use scroll_lines.unsigned_abs() instead of max(scroll_lines, 1). This matches how alt_scroll() in the same file already handles scroll_lines. Now both directions send the correct number of reports.

pub fn alt_scroll(scroll_lines: i32) -> Vec<u8> {

Testing

  • Added unit tests: scroll_report_repeats_for_negative_scroll_lines and scroll_report_repeats_for_positive_scroll_lines
  • Manually tested scrolling in tmux and neovim with mouse mode

Release Notes:

  • Fixed mouse scroll in terminal apps (tmux, neovim, etc.) only sending one scroll event when scrolling down, regardless of scroll amount

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 23, 2026
Copy link
Member

@MrSubidubi MrSubidubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, nice write-up, nice follow-up, nice test-coverage. Very nice PR, thank you!

@MrSubidubi MrSubidubi enabled auto-merge (squash) February 24, 2026 10:22
@MrSubidubi MrSubidubi merged commit fe6e528 into zed-industries:main Feb 24, 2026
29 checks passed
@emamulandalib
Copy link
Contributor Author

Thank you for the great feedback and you're welcome 😊

Anthony-Eid pushed a commit to bobbymannino/zed that referenced this pull request Feb 25, 2026
…d-industries#49931)

Follow-up to zed-industries#45600.

## Summary

Fix mouse scroll reports sending only one event when scrolling down in
terminal apps with mouse mode (tmux, neovim, etc.), regardless of how
many lines were scrolled.

## The Problem

After zed-industries#45600, trackpad scrolling speed was fixed. But when scrolling
**down** (negative `scroll_lines`), the terminal was still sending only
**one** scroll report per gesture, no matter how many lines the user
scrolled. Scrolling up worked correctly.

## Root Cause

In `scroll_report()` we had:

https://github.com/zed-industries/zed/blob/a8043dcff8f28a0443d7ec238e7f020689ebe1ff/crates/terminal/src/mappings/mouse.rs#L96

`scroll_lines` can be negative (scroll down) or positive (scroll up).
For negative values:

| scroll_lines | max(scroll_lines, 1) | Reports sent | Verdict |
|--------------|---------------------|--------------|------|
| 3 (up)       | 3                   | 3           |Right
| -3 (down)    | 1                   | 1           |WRONG|

So we always sent exactly 1 report when scrolling down, losing the
scroll magnitude.

Use `scroll_lines.unsigned_abs()` instead of `max(scroll_lines, 1)`.
This matches how `alt_scroll()` in the same file already handles
`scroll_lines`. Now both directions send the correct number of reports.

https://github.com/zed-industries/zed/blob/a8043dcff8f28a0443d7ec238e7f020689ebe1ff/crates/terminal/src/mappings/mouse.rs#L102

## Testing

- Added unit tests: `scroll_report_repeats_for_negative_scroll_lines`
and `scroll_report_repeats_for_positive_scroll_lines`
- Manually tested scrolling in tmux and neovim with mouse mode

---

Release Notes:

- Fixed mouse scroll in terminal apps (tmux, neovim, etc.) only sending
one scroll event when scrolling down, regardless of scroll amount
Caio-Ze pushed a commit to Caio-Ze/postprod-ide that referenced this pull request Mar 1, 2026
…d-industries#49931)

Follow-up to zed-industries#45600.

## Summary

Fix mouse scroll reports sending only one event when scrolling down in
terminal apps with mouse mode (tmux, neovim, etc.), regardless of how
many lines were scrolled.

## The Problem

After zed-industries#45600, trackpad scrolling speed was fixed. But when scrolling
**down** (negative `scroll_lines`), the terminal was still sending only
**one** scroll report per gesture, no matter how many lines the user
scrolled. Scrolling up worked correctly.

## Root Cause

In `scroll_report()` we had:

https://github.com/zed-industries/zed/blob/a8043dcff8f28a0443d7ec238e7f020689ebe1ff/crates/terminal/src/mappings/mouse.rs#L96

`scroll_lines` can be negative (scroll down) or positive (scroll up).
For negative values:

| scroll_lines | max(scroll_lines, 1) | Reports sent | Verdict |
|--------------|---------------------|--------------|------|
| 3 (up)       | 3                   | 3           |Right
| -3 (down)    | 1                   | 1           |WRONG|

So we always sent exactly 1 report when scrolling down, losing the
scroll magnitude.

Use `scroll_lines.unsigned_abs()` instead of `max(scroll_lines, 1)`.
This matches how `alt_scroll()` in the same file already handles
`scroll_lines`. Now both directions send the correct number of reports.

https://github.com/zed-industries/zed/blob/a8043dcff8f28a0443d7ec238e7f020689ebe1ff/crates/terminal/src/mappings/mouse.rs#L102

## Testing

- Added unit tests: `scroll_report_repeats_for_negative_scroll_lines`
and `scroll_report_repeats_for_positive_scroll_lines`
- Manually tested scrolling in tmux and neovim with mouse mode

---

Release Notes:

- Fixed mouse scroll in terminal apps (tmux, neovim, etc.) only sending
one scroll event when scrolling down, regardless of scroll amount
tahayvr pushed a commit to tahayvr/zed that referenced this pull request Mar 4, 2026
…d-industries#49931)

Follow-up to zed-industries#45600.

## Summary

Fix mouse scroll reports sending only one event when scrolling down in
terminal apps with mouse mode (tmux, neovim, etc.), regardless of how
many lines were scrolled.

## The Problem

After zed-industries#45600, trackpad scrolling speed was fixed. But when scrolling
**down** (negative `scroll_lines`), the terminal was still sending only
**one** scroll report per gesture, no matter how many lines the user
scrolled. Scrolling up worked correctly.

## Root Cause

In `scroll_report()` we had:

https://github.com/zed-industries/zed/blob/a8043dcff8f28a0443d7ec238e7f020689ebe1ff/crates/terminal/src/mappings/mouse.rs#L96

`scroll_lines` can be negative (scroll down) or positive (scroll up).
For negative values:

| scroll_lines | max(scroll_lines, 1) | Reports sent | Verdict |
|--------------|---------------------|--------------|------|
| 3 (up)       | 3                   | 3           |Right
| -3 (down)    | 1                   | 1           |WRONG|

So we always sent exactly 1 report when scrolling down, losing the
scroll magnitude.

Use `scroll_lines.unsigned_abs()` instead of `max(scroll_lines, 1)`.
This matches how `alt_scroll()` in the same file already handles
`scroll_lines`. Now both directions send the correct number of reports.

https://github.com/zed-industries/zed/blob/a8043dcff8f28a0443d7ec238e7f020689ebe1ff/crates/terminal/src/mappings/mouse.rs#L102

## Testing

- Added unit tests: `scroll_report_repeats_for_negative_scroll_lines`
and `scroll_report_repeats_for_positive_scroll_lines`
- Manually tested scrolling in tmux and neovim with mouse mode

---

Release Notes:

- Fixed mouse scroll in terminal apps (tmux, neovim, etc.) only sending
one scroll event when scrolling down, regardless of scroll amount
@emamulandalib emamulandalib deleted the fix-terminal-mouse-scroll-down branch March 4, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants