Skip to content

fix: prevent terminal viewport jumping to line 0 on tab/window switch#7

Merged
khang859 merged 2 commits intomainfrom
fix/terminal-scroll-to-top-bug
Mar 16, 2026
Merged

fix: prevent terminal viewport jumping to line 0 on tab/window switch#7
khang859 merged 2 commits intomainfrom
fix/terminal-scroll-to-top-bug

Conversation

@khang859
Copy link
Copy Markdown
Owner

Summary

  • Fix terminal scrolling to line 0 when switching tabs or OS windows while output is streaming, by tracking scroll intent with an explicit pinnedToBottom state instead of relying on xterm's buffer position (which is unreliable when the terminal is display:none or offscreen)
  • Add a floating "scroll to bottom" button that appears when the user has scrolled up, with wheel event fallback since xterm's onScroll doesn't fire for trackpad/mouse wheel viewport moves
  • After fitAddon.fit(), explicitly call scrollToBottom() when pinned, instead of trusting xterm to stay at bottom

Test plan

  • Stream output (e.g. Claude Code), switch OS windows, click back — viewport stays at bottom
  • Switch to another tab while output is streaming, switch back — viewport stays at bottom
  • Scroll up manually — "Bottom" button appears at bottom-right
  • Click "Bottom" button — snaps to bottom, button disappears
  • Resize pane while scrolled up — scroll position preserved, button stays visible
  • If nothing is happening and you switch tabs, scroll position is preserved correctly

🤖 Generated with Claude Code

khang859 and others added 2 commits March 16, 2026 11:19
Track scroll intent with an explicit `pinnedToBottom` boolean instead of
checking the instantaneous viewportY >= baseY buffer state. xterm.js
doesn't keep the viewport pinned when the terminal is display:none (tab
switches) or offscreen (OS window switches), causing fitAddon.fit() to
miscompute scroll position and reset to line 0.

Also adds a floating "scroll to bottom" button that appears when the
user has scrolled up, with wheel event fallback for trackpad detection
since xterm's onScroll doesn't fire for user-initiated viewport moves.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Combine scroll tracking (pinnedToBottom, wheelHandler, scrollCleanup)
with debounced PTY resize (debouncedPtyResize, cleanupResizeTimer)
so both features coexist.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@khang859 khang859 enabled auto-merge March 16, 2026 15:50
@khang859 khang859 disabled auto-merge March 16, 2026 15:50
@khang859 khang859 merged commit a133e40 into main Mar 16, 2026
1 check passed
@khang859 khang859 deleted the fix/terminal-scroll-to-top-bug branch March 16, 2026 15:50
khang859 added a commit that referenced this pull request Mar 29, 2026
Running/idle state indicator now implemented in copilot SessionList
via multi-signal Badge component.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant