Skip to content

fix: reset viewport on window resize to prevent content jump and loss#294

Closed
CoderGoGoGo wants to merge 1 commit intotw93:mainfrom
CoderGoGoGo:fix/resize-viewport-jump
Closed

fix: reset viewport on window resize to prevent content jump and loss#294
CoderGoGoGo wants to merge 1 commit intotw93:mainfrom
CoderGoGoGo:fix/resize-viewport-jump

Conversation

@CoderGoGoGo
Copy link
Copy Markdown

Summary

  • Reset all pane viewports to bottom after every window resize in apply_dimensions(), preventing content from appearing to jump or becoming inaccessible
  • Limit pre-prune blank line removal in Screen::resize() to avoid cumulative content loss during repeated resizes

Problem

When resizing the terminal window:

  1. The last line of content jumps upward
  2. Cannot scroll up to see previous content
  3. Repeated resizes progressively clear terminal content

Root Cause

physical_top shifts on resize because both lines.len() and physical_rows change, but PaneState::viewport was never adjusted. Additionally, the pre-prune loop in Screen::resize() had no upper bound, causing cumulative content loss.

Test Plan

  • Output several screenfuls of content, then resize the window — content should not jump
  • After resize, scroll up — all previous content should be accessible
  • Rapidly resize multiple times — content should not be cleared

🤖 Generated with Claude Code

When the terminal window is resized, physical_top shifts because the
number of lines and visible rows both change. However, the stored
viewport position (PaneState::viewport) was never adjusted, causing:

1. Content appears to "jump" upward on resize
2. Unable to scroll up to see previous content
3. Repeated resizes progressively clear terminal content

Two fixes applied:

- Reset all pane viewports to bottom (None) after every resize in
  apply_dimensions(). This ensures users always see the latest output
  after a resize, regardless of live-resize or final resize.

- Limit the pre-prune blank line removal in Screen::resize() to at most
  lines.len() - physical_rows lines. Previously the loop could remove
  all blank lines below the cursor without limit, which combined with
  repeated resizes caused cumulative content loss.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@tw93
Copy link
Copy Markdown
Owner

tw93 commented Apr 20, 2026

@CoderGoGoGo 感谢 PR,问题定位是对的。调整了一下 viewport 的处理方式:resize 后对已有 viewport 做 normalize 而不是直接重置为 None,这样用户在查看历史内容时 resize 不会被拉回底部。pre-prune 的上限逻辑保留了你的思路。已合入 main。

@tw93 tw93 closed this Apr 20, 2026
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.

2 participants