这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(tui): momentum-based scrolling #10420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 5, 2025
Merged

Conversation

MendyLanda
Copy link
Contributor

@MendyLanda MendyLanda commented May 1, 2025

Description

#10415 Adds momentum-based scrolling to the TUI for a smoother and more natural scroll experience.

Testing Instructions

  1. Run a long-running task that prints many lines, e.g.:
perl -E '$i=1; for (1..1500) { say "[$i] " . "=" x int(rand(100) + 1); $i++ }' && read
  1. Use the TUI to scroll through the output and observe the new scrolling behavior.

@MendyLanda MendyLanda requested a review from a team as a code owner May 1, 2025 15:16
@turbo-orchestrator turbo-orchestrator bot added the needs: triage New issues get this label. Remove it after triage label May 1, 2025
Copy link

vercel bot commented May 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 3:22pm
examples-designsystem-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 3:22pm
examples-native-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 3:22pm
examples-svelte-web ❌ Failed (Inspect) May 5, 2025 3:22pm
examples-tailwind-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 3:22pm
examples-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 3:22pm
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 3:22pm

Copy link

vercel bot commented May 1, 2025

@MendyLanda is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@MendyLanda
Copy link
Contributor Author

@anthonyshew for your review.

The config values are subjective and based on personal preference. I tried to match native scrolling as closely as possible. While trackpads could benefit from custom settings, it's not possible to reliably distinguish between trackpad and mouse wheel, and behavior varies a lot across devices and OSes. This still feels like a significant improvement to me.

@anthonyshew
Copy link
Contributor

@MendyLanda, this is great! Thank you!

I tried it out and it feels much better than what we have now. Significantly better.

I'm testing with a trackpad and it felt like I would go from "no momentum" to "ALL THE MOMENTUM!!!" Could we tune the ramping? I don't have a mouse wheel around to try with so I don't know if it feels great there and re-tuning would make it feel terrible. I can suggest what values feel right to me for the trackpad if you don't have one around.

Very excited about this.

@anthonyshew
Copy link
Contributor

it's not possible to reliably distinguish between trackpad and mouse wheel, and behavior varies a lot across devices and OSes

And, yes, agree with this. Let's get to some best effort that feels good (particularly for trackpad vs. mouse wheel) as best we can.

@MendyLanda
Copy link
Contributor Author

@anthonyshew for trackpad setting you can try this:
THROTTLE_FACTOR: u8 = 3
ACCELERATION: f32 = 0.2

@MendyLanda
Copy link
Contributor Author

@anthonyshew for trackpad setting you can try this: THROTTLE_FACTOR: u8 = 3 ACCELERATION: f32 = 0.2

But this completely voids mouse wheel.

I am looking at Ghostty's implementation of this, maybe I can find some ideas. If you have any suggestion I'd love to know!

@anthonyshew
Copy link
Contributor

@anthonyshew for trackpad setting you can try this: THROTTLE_FACTOR: u8 = 3 ACCELERATION: f32 = 0.2

Confirming that these values feel great for my trackpad. 👍

@anthonyshew anthonyshew changed the title feat(tui): Momentum-Based scrolling feat(tui): momentum-based scrolling May 1, 2025
@MendyLanda
Copy link
Contributor Author

MendyLanda commented May 2, 2025

I am looking at Ghostty's implementation of this, maybe I can find some ideas.

TL;DR:
It’s impossible to detect precision scrolling (touchpad) and apply the delta conditionally. This is a limitation of crossterm (ANSI codes).
So, we have two options:

  1. Let the user toggle between touchpad and mouse wheel mode.
    [+] Scrolling always feels great.
    [–] We already have too many scroll-related keybinds, so adding another for something that’s usually a one-off isn’t ideal.

  2. Find an acceptable middle ground that works (mostly) for both.
    [+] Doesn’t add another keybind; users don’t need to know about this.
    [+] Still feels better than what we currently have.
    [–] Could be improved further.

@anthonyshew, your call. Option 2 feels more reasonable, but personally, I’d prefer option 1 😄.
If we go with option 2, these settings seem to be a good middle ground:

const ACCELERATION: f32 = 0.3; // 2.0 is optimal for mouse wheel, but higher values make the touchpad too jumpy.
const DECAY_TIME: Duration = Duration::from_millis(350); // less than 300ms is too fast for mouse wheel; 350ms slightly favors mouse wheel.
const THROTTLE_FACTOR: u8 = 3; // Lower values make the touchpad unusable.

@anthonyshew
Copy link
Contributor

That feels great for me on trackpad. Soft-approved from me! Looking for a teammate with a mouse to confirm their mouse feels right...

@chris-olszewski
Copy link
Member

Thank you so much for the PR! I suggested some changes in MendyLanda#1 that make it feel a little better with a mouse scroll wheel.

@MendyLanda
Copy link
Contributor Author

Thank you so much for the PR! I suggested some changes in MendyLanda#1 that make it feel a little better with a mouse scroll wheel.

Thank you! This was the missing piece! feels great on both my mouse (logitech mx2) and my mb trackpad!

Copy link
Member

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

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

This is a great addition. Thank you again for the PR!

@chris-olszewski chris-olszewski merged commit d67a6c3 into vercel:main May 5, 2025
33 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: triage New issues get this label. Remove it after triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants