Skip to content

fix(tui): preserve scroll position when tasks complete and scroll faster#31898

Merged
AgentEnder merged 3 commits intomasterfrom
tui-scrolling
Jul 16, 2025
Merged

fix(tui): preserve scroll position when tasks complete and scroll faster#31898
AgentEnder merged 3 commits intomasterfrom
tui-scrolling

Conversation

@AgentEnder
Copy link
Copy Markdown
Member

Current Behavior

Scroll position gets reset when unrelated tasks finish. Additionally, scrolling is just really slow.

Expected Behavior

This pull request introduces momentum-based scrolling and improves scroll position preservation across terminal panes and pseudo-terminal instances (PtyInstance). It also adds a new ScrollMomentum module to manage scrolling behavior dynamically based on user input patterns. The changes enhance user experience by making scrolling smoother and more intuitive, especially during rapid or sustained scrolling.

Scroll Momentum Enhancements:

  • Added the ScrollMomentum module to calculate dynamic scrolling behavior based on time intervals and direction changes, allowing for accelerated scrolling during sustained input. (packages/nx/src/native/tui/scroll_momentum.rs, packages/nx/src/native/tui/scroll_momentum.rsR1-R101)
  • Integrated momentum-based scrolling into TerminalPaneData and PtyInstance, replacing static scroll methods with dynamic ones (scroll_up and scroll_down) that use calculated momentum values. (packages/nx/src/native/tui/components/terminal_pane.rs, [1]; packages/nx/src/native/tui/pty.rs, [2] [3] [4]

Scroll Position Preservation:

  • Enhanced PtyInstance to preserve scroll position during terminal resize operations, ensuring better continuity when dimensions change. (packages/nx/src/native/tui/pty.rs, [1] [2]

Code Improvements:

  • Added momentum reset logic when switching interactive modes or changing scroll direction to avoid abrupt changes in scrolling behavior. (packages/nx/src/native/tui/components/terminal_pane.rs, [1]; packages/nx/src/native/tui/scroll_momentum.rs, [2]
  • Updated TerminalPaneData and PtyInstance constructors to initialize ScrollMomentum instances for consistent scrolling state management. (packages/nx/src/native/tui/components/terminal_pane.rs, [1]; packages/nx/src/native/tui/pty.rs, [2] [3]

These changes collectively improve the usability of terminal panes and pseudo-terminal instances by making scrolling more responsive and preserving user context during resize events.

Related Issue(s)

Fixes #

@AgentEnder AgentEnder requested review from a team as code owners July 11, 2025 16:23
@AgentEnder AgentEnder requested review from Cammisuli and xiongemi July 11, 2025 16:23
@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 11, 2025

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

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Jul 16, 2025 9:59pm

Comment thread packages/nx/src/native/tui/pty.rs Outdated
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Jul 11, 2025

View your CI Pipeline Execution ↗ for commit 8203d47

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 28m 25s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 16s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 2s View ↗
nx documentation ✅ Succeeded 1m 30s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-16 22:22:09 UTC

Comment thread packages/nx/src/native/tui/components/terminal_pane.rs
AgentEnder and others added 3 commits July 16, 2025 17:46
When a task completes, the TUI would trigger a resize operation on all PTY
instances, causing the scroll position of the currently viewed task to reset
to the bottom. This was particularly jarring when viewing long task output
while other tasks completed in the background.

The root cause was two-fold:
1. `print_task_terminal_output` would create new PTY instances for completed
   tasks, losing any existing scroll state
2. The `resize` method would always recreate the parser and reset scroll
   position, even when dimensions hadn't changed

Fixed by:
- Preserving existing PTY instances when appending final task output
- Skipping resize operations when dimensions haven't actually changed
- Intelligently preserving scroll position during necessary resize operations

This ensures that users can scroll through task output without having their
view position disrupted by unrelated task completions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Refactored scrolling logic to provide momentum-based scrolling across all
terminal interactions. When users scroll rapidly (keyboard or mouse), the
scroll speed increases progressively, making it much faster to navigate
through long task output.

Key changes:
- Created reusable `ScrollMomentum` struct that tracks timing and direction
- Momentum builds when scrolling within 150ms intervals (max 20 lines/scroll)
- Resets when direction changes or 150ms timeout is exceeded
- Applied to both terminal pane scrolling and PTY interactive arrow keys
- Unified scroll behavior across keyboard (arrows, j/k, ctrl+u/d) and mouse

This provides a much smoother experience when reviewing long build logs or
test output, allowing users to quickly scroll to different sections while
maintaining fine control for precise navigation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@AgentEnder AgentEnder merged commit 8b4b3e9 into master Jul 16, 2025
5 checks passed
@AgentEnder AgentEnder deleted the tui-scrolling branch July 16, 2025 22:22
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants