Skip to content

fix: preserve scroll position when terminal shrinks#638

Open
mekineer-com wants to merge 1 commit intolxqt:masterfrom
mekineer-com:fix/resize-scroll-position
Open

fix: preserve scroll position when terminal shrinks#638
mekineer-com wants to merge 1 commit intolxqt:masterfrom
mekineer-com:fix/resize-scroll-position

Conversation

@mekineer-com
Copy link
Copy Markdown

Summary

  • When the terminal shrinks vertically, Screen::resizeImage() pushes excess screen lines into history to keep the cursor in view. ScreenWindow::notifyOutputChanged() adjusts _currentLine for dropped lines (history overflow) but not for these resize-pushed lines in the non-tracking-output path, causing the viewport to jump towards the top of the scrollback.
  • Track pushed lines in a new _resizePushedLines counter, advance _currentLine by that amount in the non-tracking path, reset in showBulk().

Reproduction

  1. Open qterminal, run a command that produces lots of output
  2. Scroll up to the middle of the scrollback
  3. Shrink the terminal window vertically by dragging the bottom edge
  4. Observe the scrollbar thumb jumps towards the top instead of staying anchored

Test plan

  • Shrink terminal while scrolled up in scrollback — viewport should stay anchored
  • Shrink terminal while at bottom (tracking output) — should stay at bottom
  • Rapid resizes (drag edge quickly) — no drift due to accumulated pushes
  • History-limited terminal filling up during resize — droppedLines still handled correctly

When the terminal's visible area shrinks, Screen::resizeImage() pushes
excess screen lines into history to keep the cursor in view. However,
ScreenWindow::notifyOutputChanged() did not adjust _currentLine for
this history growth in the non-tracking-output path, causing the
viewport to jump towards the top of the scrollback.

This is noticeable in any layout where the terminal widget shares
vertical space with another widget that can grow (e.g. a text editor
strip), but also affects plain window resizes — shrinking a terminal
window while scrolled up in the scrollback causes a visible position
jump.

Track the number of lines pushed to history during resizeImage() in a
new _resizePushedLines counter. In the non-tracking path of
notifyOutputChanged(), advance _currentLine by that amount so the
bottom-visible line stays anchored. The counter accumulates across
batched resizes and resets in showBulk() alongside scrolledLines and
droppedLines.
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