fix: terminal scroll preservation on tab switch and alt buffer exit #2858
+40
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2384, fixes #2790
Two related scroll-to-top bugs that have been driving me crazy:
Tab switch scroll jump: Switching between tabs would reset the terminal scroll position to the top. The issue was that intermediate tab repositioning during the switch triggered resize events that reset the viewport. Fix: skip intermediate tab repositioning for already-initialized tabs in
emain-window.ts, and guardhandleResizeto only restore scroll if dimensions actually changed.Alt buffer exit scroll jump: Exiting a full-screen program (htop, vim, less, etc.) would scroll the terminal to the top. Fix: save the
baseYscroll position via xterm.jsonBufferChange, then restore it withrequestAnimationFrameafter the buffer switch completes. Also added an auto-scroll guard so it doesn't interfere if the user was already at the bottom.Heads up — this fixes it in most cases but I've still seen occasional jumps in edge cases. Probably needs a couple more trigger points caught, but it's way better than before.
Test plan
htoporless /etc/hosts, scroll around, quit — terminal should not jump to topvim, edit something, quit — scroll should hold