Skip to content

Commit 14fc559

Browse files
committed
Correctly handle edge case with exactly filled line
1 parent 2c3b9cf commit 14fc559

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

PSReadLine/Render.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,18 @@ static int FindCommonPrefixLength(string leftStr, string rightStr)
326326

327327
// If we had to wrap to render everything, update _initialY
328328
var endPoint = ConvertOffsetToPoint(currentBuffer.Length);
329-
int physicalLine = endPoint.Y - _initialY;
330-
if (_initialY + physicalLine > bufferHeight)
329+
if (endPoint.Y >= bufferHeight)
331330
{
331+
332332
// We had to scroll to render everything, update _initialY.
333-
_initialY = bufferHeight - physicalLine;
333+
int offset = 1; // Base case to handle zero-indexing.
334+
if (endPoint.X == 0)
335+
{
336+
// The line hasn't actually wrapped yet because we have exactly filled the line.
337+
offset -= 1;
338+
}
339+
int scrolledLines = endPoint.Y - bufferHeight + offset;
340+
_initialY -= scrolledLines;
334341
}
335342

336343
// Preserve the current render data.
@@ -347,8 +354,8 @@ static int FindCommonPrefixLength(string leftStr, string rightStr)
347354
if (point.Y == bufferHeight)
348355
{
349356
// The cursor top exceeds the buffer height and it hasn't already wrapped,
350-
// so we need to scroll up the buffer by 1 line.
351-
if (point.X == 0)
357+
// (because we have exactly filled the line) so we need to scroll up the buffer by 1 line.
358+
if (point.X == 0 && !currentBuffer.EndsWith("\n"))
352359
{
353360
_console.Write("\n");
354361
}

0 commit comments

Comments
 (0)