Skip to content

Commit

Permalink
Fix colors getting lost on reflow (#17568)
Browse files Browse the repository at this point in the history
The "copy the remaining attributes" loop assumes that it has full
ownership over the rows that it copies. For that to be true,
we have to of course make sure that the current write-cursor
is at a fresh, new row in the first place.

## Validation Steps Performed
* In a new pwsh tab with 120 colums:
  ``Write-Host -NoNewline "`e[36m$('a'*120)`e[m"; sleep 10``
* Resize the window wider
* Color doesn't get lost
  • Loading branch information
lhecker authored Jul 30, 2024
1 parent 295cd17 commit 2f43886
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,15 @@ void TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer, const View
}
}

// The for loop right after this if condition will copy entire rows of attributes at a time.
// This assumes of course that the "write cursor" (newX, newY) is at the start of a row.
// If we didn't check for this, we may otherwise copy attributes from a later row into a previous one.
if (newX != 0)
{
newX = 0;
newY++;
}

// Finish copying buffer attributes to remaining rows below the last
// printable character. This is to fix the `color 2f` scenario, where you
// change the buffer colors then resize and everything below the last
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/out/ut_textbuffer/ReflowTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,13 @@ namespace
TestBuffer{
{ 2, 5 }, // reduce width aggressively
{
{ L" ", false },
{ L" ", true },
{ L" ", true },
{ L" ", true },
{ L" ", true },
{ L" ", false },
},
{ 1, 0 },
{ 1, 4 },
},
},
},
Expand Down

0 comments on commit 2f43886

Please sign in to comment.