Fix CRLF translation when DISABLE_NEWLINE_AUTO_RETURN is reset (#18781)

We can't do the `pos.x != 0` check. Instead, I replaced it with
a CR check to avoid redundant CRs during CRLF translation.

Closes #18735

## Validation Steps Performed
* Run the repro in the linked issue
This commit is contained in:
Leonard Hecker 2025-04-15 02:57:30 +02:00 committed by GitHub
parent 8b01f546cb
commit 354e05d713
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -269,17 +269,26 @@ void WriteCharsLegacy(SCREEN_INFORMATION& screenInfo, const std::wstring_view& t
case UNICODE_LINEFEED:
{
auto pos = cursor.GetPosition();
if (WI_IsFlagClear(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN) && pos.x != 0)
// If DISABLE_NEWLINE_AUTO_RETURN is not set, any LF behaves like a CRLF.
if (WI_IsFlagClear(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN))
{
pos.x = 0;
// This causes the current \n to be replaced with a \r\n in the ConPTY VT output.
wch = 0;
lastCharWrapped = true;
// Setting wch=0 and lastCharWrapped=true will cause the code at the end
// of the loop to emit a CRLF. However, we only do this if the preceding
// character isn't already a CR. We don't want to emit CR CR LF after all.
if (it == beg || it[-1] != '\r')
{
wch = 0;
lastCharWrapped = true;
}
}
textBuffer.GetMutableRowByOffset(pos.y).SetWrapForced(false);
pos.y = pos.y + 1;
AdjustCursorPosition(screenInfo, pos, psScrollY);
break;
}
case UNICODE_CARRIAGERETURN: