Skip to content

Commit 7c82577

Browse files
msftrncsdaxian-dbw
authored andcommitted
Handle cursor being moved off the end of buffer in MoveCursor. (#1146)
1 parent 09300c0 commit 7c82577

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

PSReadLine/Render.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,25 @@ private void MoveCursor(int newCursor)
992992
return;
993993
}
994994

995-
_console.SetCursorPosition(point.X, point.Y);
995+
if (point.Y == _console.BufferHeight)
996+
{
997+
// The cursor top exceeds the buffer height, so adjust the initial cursor
998+
// position and the to-be-set cursor position for scrolling up the buffer.
999+
_initialY -= 1;
1000+
point.Y -= 1;
1001+
1002+
// Insure the cursor is on the last line of the buffer prior
1003+
// to issuing a newline to scroll the buffer.
1004+
_console.SetCursorPosition(point.X, point.Y);
1005+
1006+
// Scroll up the buffer by 1 line.
1007+
_console.Write("\n");
1008+
}
1009+
else
1010+
{
1011+
_console.SetCursorPosition(point.X, point.Y);
1012+
}
1013+
9961014
_current = newCursor;
9971015
}
9981016

0 commit comments

Comments
 (0)