Skip to content

Commit aa4f616

Browse files
committed
Fix ClearScreen to properly scroll
The previous change scrolled the wrong test, losing the bottom instead of the top of the buffer.
1 parent 3025a52 commit aa4f616

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

PSReadLine/Changes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ New features:
1313
Bug fixes:
1414
* Occasional exception with AcceptAndGetNext (Ctrl+O) followed by something other than Enter
1515
* Event handlers that register for the engine event PowerShell.OnIdle should work now.
16-
* ClearScreen now just clears the visible screen, not the entire buffer.
16+
* ClearScreen now scrolls the screen to preserve as much output as possible
1717
* Fix exception on error input during rendering after certain keywords like process, begin, or end.
1818
* Fix exception after undo from menu completion
1919
* Support CancelLine (Ctrl+C) and Abort (Ctrl+G in emacs) to cancel DigitArgument

PSReadLine/Movement.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,17 @@ public static void GotoBrace(ConsoleKeyInfo? key = null, object arg = null)
413413
/// </summary>
414414
public static void ClearScreen(ConsoleKeyInfo? key = null, object arg = null)
415415
{
416-
int top = Console.WindowTop;
417-
WriteBlankLines(Console.WindowHeight, top);
418-
_singleton._initialY = top;
419-
_singleton.Render();
416+
if (_singleton._initialY + Console.WindowHeight > Console.BufferHeight)
417+
{
418+
var scrollCount = _singleton._initialY - Console.WindowTop;
419+
ScrollBuffer(scrollCount);
420+
_singleton._initialY -= scrollCount;
421+
Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - scrollCount);
422+
}
423+
else
424+
{
425+
Console.SetWindowPosition(0, _singleton._initialY);
426+
}
420427
}
421428

422429
// Try to convert the arg to a char, return 0 for failure

0 commit comments

Comments
 (0)