Skip to content

Fix VT scroll margins leaking between pages - #20523

Open
maoyouaa wants to merge 4 commits into
microsoft:mainfrom
maoyouaa:mao/fix-vt-page-margins
Open

Fix VT scroll margins leaking between pages#20523
maoyouaa wants to merge 4 commits into
microsoft:mainfrom
maoyouaa:mao/fix-vt-page-margins

Conversation

@maoyouaa

@maoyouaa maoyouaa commented Aug 7, 2026

Copy link
Copy Markdown

Summary of the Pull Request

Store VT scroll margins on each page's TextBuffer so DECSTBM and DECSLRM settings do not leak between VT pages.

Preserve the existing behavior of sharing margins across main and alternate screen buffers.

References and Relevant Issues

Closes #19625

Detailed Description of the Pull Request / Additional comments

  • Moves scroll-margin storage from AdaptDispatch to TextBuffer.
  • Preserves margins during resize and reflow.
  • Saves and restores margins when switching visible VT pages.
  • Transfers margins in both directions when switching between main and alternate screen buffers.
  • Keeps cursor-property copying separate from margin state.
  • Uses the target page's margins for movement, queries, and Sixel handling.

No documentation or schema changes are required.

Validation Steps Performed

  • Built Host.UnitTests.vcxproj and Adapter.UnitTests.vcxproj for Debug x64.
  • PageMarginsAreIndependentTest: 1 passed.
  • VtScrollMarginsAltBufferInheritance: 1 passed.
  • PageMovementWithOriginModeTest: 1 passed.
  • Adapter suite: 277 passed, 132 skipped, 0 failed.
  • TextBufferTests: 70 passed, 0 failed.
  • Alt-buffer host tests: 24 passed, 0 failed.
  • clang-format dry-run passed.
  • git diff --check passed with CRLF handling.

PR Checklist

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@maoyouaa
maoyouaa marked this pull request as ready for review August 8, 2026 08:52
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@j4james

Copy link
Copy Markdown
Collaborator

I haven't actually tested this PR, but I think it may require some additional code in the PageManager::MoveTo method to adjust the cursor position when moving between pages with different margins, but only if the origin mode is set.

When that mode is set, the cursor position is relative to the margin origin (now potentially different per page), so the absolute cursor position can change when moving between pages. It may also be necessary to clamp the position along the bottom right boundaries if moving to a page with smaller margins, otherwise the cursor can end up outside the permitted range.

@maoyouaa

Copy link
Copy Markdown
Author

Thanks, you were right. I updated PageManager::MoveTo to preserve the cursor position relative to the page margins when origin mode is set, and to clamp it to the target page's right and bottom margin boundaries.

I also added PageMovementWithOriginModeTest covering both coupled and uncoupled page movement, including moves to a page with smaller margins. The full adapter suite passes with 277 passed and 132 skipped, and the alternate-buffer margin regression still passes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think the code looks good. I just have a couple of suggestions which I think might improve the readability.

Comment thread src/terminal/adapter/PageManager.cpp Outdated
Comment thread src/terminal/adapter/adaptDispatch.cpp
Comment thread src/terminal/adapter/PageManager.cpp Outdated
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.

VT margins are meant to be tracked separately for each page

2 participants