Skip to content

Conversation

@raunak0400
Copy link

Fix: Per-Page Scroll Margins (DECSTBM/DECSLRM)

Issue #19625

Scroll margins were tracked globally instead of per-page, causing margins set on one page to incorrectly affect other pages.

Bug Scenario:

printf "\e#8\e[2 P\e[9;15r\e[1 P\e[999B\n\n\n\n\n\n\n"
  • Fill screen with DECALN
  • Switch to page 2 → Set margins 9-15
  • Switch to page 1 → Scroll with linefeeds
  • Problem: Page 2's margins affected page 1's scrolling

Root Cause

_scrollMargins was a single member variable in AdaptDispatch, shared across all pages. VT spec requires margins to be tracked per-page.

Solution

1. Added Per-Page Storage (PageManager.hpp/cpp)

  • Added std::array<til::inclusive_rect, MAX_PAGES> _scrollMargins{}
  • Added GetScrollMargins(pageNumber) and SetScrollMargins(pageNumber, margins)
  • Reset margins when PageManager resets

2. Updated Margin Management (adaptDispatch.hpp/cpp)

  • Removed global _scrollMargins variable
  • Updated _GetVerticalMargins() and _GetHorizontalMargins() to use page-specific margins
  • Updated _DoSetTopBottomScrollingMargins() and _DoSetLeftRightScrollingMargins() to store margins per-page

3. Updated Tests (adapterTest.cpp)

  • Modified ScrollMarginsTest to access margins via PageManager
  • Added PerPageScrollMarginsTest to verify page isolation

Files Modified

  • src/terminal/adapter/PageManager.hpp
  • src/terminal/adapter/PageManager.cpp
  • src/terminal/adapter/adaptDispatch.hpp
  • src/terminal/adapter/adaptDispatch.cpp
  • src/terminal/adapter/ut_adapter/adapterTest.cpp

Result

Each page now maintains independent scroll margins
Margins set on page 2 no longer affect page 1
Margins persist correctly when switching between pages
Complies with VT programmer's reference specification

@raunak0400
Copy link
Author

@microsoft-github-policy-service agree

@raunak0400
Copy link
Author

what should i supposed to do now

@j4james
Copy link
Collaborator

j4james commented Dec 7, 2025

Was this code written by an LLM by any chance?

@raunak0400
Copy link
Author

@j4james No, its completely written by me . can you tell me if there's any change ? Or can you merge it please

@j4james
Copy link
Collaborator

j4james commented Dec 7, 2025

It can't be merged until it has been reviewed and approved by someone at Microsoft, and that's not something I can do. But my suggestion to you would be to get the code to compile first, because I suspect you'll find there's a lot more work you need to do.

til::CoordType _visiblePageNumber = 1;
static constexpr til::CoordType MAX_PAGES = 6;
mutable std::array<std::unique_ptr<TextBuffer>, MAX_PAGES> _buffers;
std::array<til::inclusive_rect, MAX_PAGES> _scrollMargins{};
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm... should we perhaps store the margins directly on the TextBuffer?

@DHowett
Copy link
Member

DHowett commented Dec 10, 2025

what should i supposed to do now

Can you send a screenshot of your development environment showing all the tests passing?

Thanks!

@DHowett DHowett added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 10, 2025
@raunak0400 raunak0400 closed this Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants