Skip to content

Sync the scrollbar position to the buffer after a resize - #6342

Open
YogiOnCode wants to merge 1 commit into
xtermjs:masterfrom
YogiOnCode:fix/6172-scrollbar-position-after-resize
Open

YogiOnCode wants to merge 1 commit into
xtermjs:masterfrom
YogiOnCode:fix/6172-scrollbar-position-after-resize

Conversation

@YogiOnCode

Copy link
Copy Markdown

Fixes #6172

A resize can reflow the buffer and move ydisp without firing onScroll. Viewport's onResize handler called queueSync(), which runs _sync(this._latestYDisp), and _sync only moves the scrollbar when ydisp !== this._latestYDisp. So after a terminal that had been scrolled up was resized, the scrollbar kept its pixel offset from the old size, and the next wheel tick scrolled by the whole difference (871 → 572 in the issue's repro).

The fix clears _latestYDisp on resize, exactly as the onBufferActivate handler right below already does. The queued sync then reads ydisp from the buffer and sets the scroll position. Resizes are still coalesced to one sync per frame; the only added work is one setScrollPosition per resize frame. A smooth scroll in flight during a resize now ends at the buffer's position, which the issue argues a resize should do anyway.

Tests

  • New Playwright test in test/playwright/Terminal.test.ts (buffer › scrollbar follows viewportY after a resize reflows a scrolled-up buffer), following the issue's repro: 300 long lines at 60 cols, scroll up 20, resize to 120 and back, then check the scrollbar row equals viewportY. Fails before the change, passes after.
  • npm run test-unit: 2445 passing. lint-changes clean.
  • npm run test-integration-chromium: core 428 passed; all addon suites pass except addon-fit (5) and addon-image (2), which fail identically on this machine without the change (Windows 11, local environment).

A resize can reflow the buffer and move ydisp without firing onScroll. The
onResize handler synced against the remembered _latestYDisp, so _sync never
moved the scrollbar and it kept the pixel offset from the old size. The next
wheel tick then scrolled by the whole error (hundreds of lines).

Clear _latestYDisp on resize, as onBufferActivate already does, so the queued
sync reads ydisp from the buffer and sets the scroll position.

Fixes xtermjs#6172
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.

A resize updates the scrollbar's extent but not its position, so the next wheel tick jumps hundreds of lines

1 participant