[PR #5122] Correct scrolling invalidation region for tmux in pty w/ bitmap #26120

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

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

State: closed
Merged: Yes


Correct scrolling invalidation region for tmux in pty w/ bitmap

Add tracing for circling and scrolling operations. Fix improper
invalidation within AdjustCursorPosition routine in the subsection about
scrolling down at the bottom with a set of margins enabled.

References

Detailed Description of the Pull Request / Additional comments

  • This occurs when there is a scroll region restriction applied and a
    newline operation is performed to attempt to spin the contents of just
    the scroll region. This is a frequent behavior of tmux.
  • Right now, the Terminal doesn't support any sort of "scroll content"
    operation, so what happens here generally speaking is that the PTY in
    the ConHost will repaint everything when this happens.
  • The PTY when doing AdjustCursorPosition with a scroll region
    restriction would do the following things:
  1. Slide literally everything in the direction it needed to go to take
    advantage of rotating the circular buffer. (This would force a
    repaint in PTY as the PTY always forces repaint when the buffer
    circles.)
  2. Copy the lines that weren't supposed to move back to where they were
    supposed to go.
  3. Backfill the "revealed" region that encompasses what was supposed to
    be the newline.
  • The invalidations for the three operations above were:
  1. Invalidate the number of rows of the delta at the top of the buffer
    (this part was wrong)
  2. Invalidate the lines that got copied back into position (probably
    unnecessary, but OK)
  3. Invalidate the revealed/filled-with-spaces line (this is good).
  • When we were using a simple single rectangle for invalidation, the
    union of the top row of the buffer from 1 and the bottom row of the
    buffer from 2 (and 3 was irrelevant as it was already unioned it)
    resulted in repainting the entire buffer and all was good.

  • When we switched to a bitmap, it dutifully only repainted the top line
    and the bottom two lines as the middle ones weren't a consequence of
    intersect.

  • The logic was wrong. We shouldn't be invalidating rows-from-the-top
    for the amount of the delta. The 1 part should be invalidating
    everything BUT the lines that were invalidated in parts 2 and 3.
    (Arguably part 2 shouldn't be happening at all, but I'm not optimizing
    for that right now.)

  • So this solves it by restoring an entire screen repaint for this sort
    of slide data operation by giving the correct number of invalidated
    lines to the bitmap.

Validation Steps Performed

  • Manual validation with the steps described in #5104
  • Automatic test ConptyRoundtripTests::ScrollWithMargins.

Closes #5104

**Original Pull Request:** https://github.com/microsoft/terminal/pull/5122 **State:** closed **Merged:** Yes --- Correct scrolling invalidation region for tmux in pty w/ bitmap Add tracing for circling and scrolling operations. Fix improper invalidation within AdjustCursorPosition routine in the subsection about scrolling down at the bottom with a set of margins enabled. ## References - Introduced with #5024 ## Detailed Description of the Pull Request / Additional comments - This occurs when there is a scroll region restriction applied and a newline operation is performed to attempt to spin the contents of just the scroll region. This is a frequent behavior of tmux. - Right now, the Terminal doesn't support any sort of "scroll content" operation, so what happens here generally speaking is that the PTY in the ConHost will repaint everything when this happens. - The PTY when doing `AdjustCursorPosition` with a scroll region restriction would do the following things: 1. Slide literally everything in the direction it needed to go to take advantage of rotating the circular buffer. (This would force a repaint in PTY as the PTY always forces repaint when the buffer circles.) 2. Copy the lines that weren't supposed to move back to where they were supposed to go. 3. Backfill the "revealed" region that encompasses what was supposed to be the newline. - The invalidations for the three operations above were: 1. Invalidate the number of rows of the delta at the top of the buffer (this part was wrong) 2. Invalidate the lines that got copied back into position (probably unnecessary, but OK) 3. Invalidate the revealed/filled-with-spaces line (this is good). - When we were using a simple single rectangle for invalidation, the union of the top row of the buffer from 1 and the bottom row of the buffer from 2 (and 3 was irrelevant as it was already unioned it) resulted in repainting the entire buffer and all was good. - When we switched to a bitmap, it dutifully only repainted the top line and the bottom two lines as the middle ones weren't a consequence of intersect. - The logic was wrong. We shouldn't be invalidating rows-from-the-top for the amount of the delta. The 1 part should be invalidating everything BUT the lines that were invalidated in parts 2 and 3. (Arguably part 2 shouldn't be happening at all, but I'm not optimizing for that right now.) - So this solves it by restoring an entire screen repaint for this sort of slide data operation by giving the correct number of invalidated lines to the bitmap. ## Validation Steps Performed - Manual validation with the steps described in #5104 - Automatic test `ConptyRoundtripTests::ScrollWithMargins`. Closes #5104
claunia added the pull-request label 2026-01-31 09:14:04 +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#26120