[PR #15930] COOKED_READ_DATA: Fix scrolling under ConPTY #30782

Open
opened 2026-01-31 09:42:54 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/15930

State: closed
Merged: Yes


This commit fixes 3 bugs:

  • COOKED_READ_DATA failed to initialize its _distanceCursor and
    _distanceEnd members. I took this as an opportunity to make them
    ptrdiff_t, to reduce the likelihood of overflows in the future.
  • COOKED_READ_DATA::_writeChars added scrollY to the written
    distance, even though WriteCharsLegacy writes a negative value into
    that out parameter. This was fixed by changing WriteCharsLegacy to
    write positive values and by adding a debug assertion.
  • StreamScrollRegion calls IncrementCircularBuffer which causes a
    synchronous (!) ConPTY flush to the output pipe (side note: this is
    the primary reason why newlines are so slow in ConPTY).
    Since cooked reads are supposed to behave like a pager and not write
    into the scrollback, we temporarily mark the buffer as inactive
    which prevents TextBuffer from snitching about it to VtEngine.

Even after this change, there's still some weird behavior left:

  • You cannot move your cursor back beyond (0,0), because this isn't a
    real pager-like implementation. That might be a neat future extension.
  • Writing a lot of text and pressing Ctrl+C doesn't properly place the
    cursor and scroll the buffer, unless the cursor is at the end.
    That might also be worth investigating in the future (minor issue).
  • When the viewport is full, backspacing more than 1 line of text
    (using Ctrl+Backspace) doesn't erase all of the affected lines,
    because COOKED_READ_DATA::_erase uses the same WriteCharsLegacy
    function to write whitespace to erase that text. It's only gone
    after typing one more character.
    I've written the code to mostly fix this, but decided against it
    as I considered the problem to be too niche to warrant extra code.

Closes #15899

Validation Steps Performed

  • Generate some text to paste in PowerShell:
    "" + (0..512 | % { "word" + $_.ToString().PadLeft(4, "0") })
    
  • Launch cmd.exe and paste that text
  • No flickering
  • No writing into the scrollback
  • No weird behavior when backspacing
**Original Pull Request:** https://github.com/microsoft/terminal/pull/15930 **State:** closed **Merged:** Yes --- This commit fixes 3 bugs: * `COOKED_READ_DATA` failed to initialize its `_distanceCursor` and `_distanceEnd` members. I took this as an opportunity to make them `ptrdiff_t`, to reduce the likelihood of overflows in the future. * `COOKED_READ_DATA::_writeChars` added `scrollY` to the written distance, even though `WriteCharsLegacy` writes a negative value into that out parameter. This was fixed by changing `WriteCharsLegacy` to write positive values and by adding a debug assertion. * `StreamScrollRegion` calls `IncrementCircularBuffer` which causes a synchronous (!) ConPTY flush to the output pipe (side note: this is the primary reason why newlines are so slow in ConPTY). Since cooked reads are supposed to behave like a pager and not write into the scrollback, we temporarily mark the buffer as inactive which prevents `TextBuffer` from snitching about it to VtEngine. Even after this change, there's still some weird behavior left: * You cannot move your cursor back beyond (0,0), because this isn't a real pager-like implementation. That might be a neat future extension. * Writing a lot of text and pressing Ctrl+C doesn't properly place the cursor and scroll the buffer, unless the cursor is at the end. That might also be worth investigating in the future (minor issue). * When the viewport is full, backspacing more than 1 line of text (using Ctrl+Backspace) doesn't erase all of the affected lines, because `COOKED_READ_DATA::_erase` uses the same `WriteCharsLegacy` function to write whitespace to erase that text. It's only gone after typing one more character. I've written the code to mostly fix this, but decided against it as I considered the problem to be too niche to warrant extra code. Closes #15899 ## Validation Steps Performed * Generate some text to paste in PowerShell: ```pwsh "" + (0..512 | % { "word" + $_.ToString().PadLeft(4, "0") }) ``` * Launch cmd.exe and paste that text * No flickering ✅ * No writing into the scrollback ✅ * No weird behavior when backspacing ✅
claunia added the pull-request label 2026-01-31 09:42:54 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30782