Skip to content

Commit 354e05d

Browse files
authored
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
1 parent 8b01f54 commit 354e05d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/host/_stream.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,26 @@ void WriteCharsLegacy(SCREEN_INFORMATION& screenInfo, const std::wstring_view& t
269269
case UNICODE_LINEFEED:
270270
{
271271
auto pos = cursor.GetPosition();
272-
if (WI_IsFlagClear(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN) && pos.x != 0)
272+
273+
// If DISABLE_NEWLINE_AUTO_RETURN is not set, any LF behaves like a CRLF.
274+
if (WI_IsFlagClear(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN))
273275
{
274276
pos.x = 0;
275-
// This causes the current \n to be replaced with a \r\n in the ConPTY VT output.
276-
wch = 0;
277-
lastCharWrapped = true;
277+
278+
// Setting wch=0 and lastCharWrapped=true will cause the code at the end
279+
// of the loop to emit a CRLF. However, we only do this if the preceding
280+
// character isn't already a CR. We don't want to emit CR CR LF after all.
281+
if (it == beg || it[-1] != '\r')
282+
{
283+
wch = 0;
284+
lastCharWrapped = true;
285+
}
278286
}
279287

280288
textBuffer.GetMutableRowByOffset(pos.y).SetWrapForced(false);
281289
pos.y = pos.y + 1;
282290
AdjustCursorPosition(screenInfo, pos, psScrollY);
291+
283292
break;
284293
}
285294
case UNICODE_CARRIAGERETURN:

0 commit comments

Comments
 (0)