From bd62ec216def9d328988fcf645780613fe94de36 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Fri, 8 Nov 2019 01:18:26 -0600 Subject: [PATCH] Handle cursor being moved to end of buffer. Handle when `MoveCursor()` attempts to move the cursor to the end of the terminal buffer, same as `Render()`, by issueing a line feed to force a scroll. Fixes #1144. --- PSReadLine/Render.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 02cb1da12..48feb583a 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -992,7 +992,25 @@ private void MoveCursor(int newCursor) return; } - _console.SetCursorPosition(point.X, point.Y); + if (point.Y == _console.BufferHeight) + { + // The cursor top exceeds the buffer height, so adjust the initial cursor + // position and the to-be-set cursor position for scrolling up the buffer. + _initialY -= 1; + point.Y -= 1; + + // Insure the cursor is on the last line of the buffer prior + // to issuing a newline to scroll the buffer. + _console.SetCursorPosition(point.X, point.Y); + + // Scroll up the buffer by 1 line. + _console.Write("\n"); + } + else + { + _console.SetCursorPosition(point.X, point.Y); + } + _current = newCursor; }