Skip to content

Commit 51bc372

Browse files
committed
Fix ScrollDisplayToCursor to work better
Fixes #190
1 parent 17856e9 commit 51bc372

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

PSReadLine/Changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Bug fixes:
2020
* History recall now ignores command lines from other currently running sessions, but you can
2121
still find command lines from those sessions when searching history.
2222
* Color any non-whitespace prompt character when there is an error, not just non-characters
23+
* ScrollDisplayToCursor works a little better now.
2324

2425
New functions:
2526
* ValidateAndAcceptLine

PSReadLine/Render.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,20 @@ public static void ScrollDisplayTop(ConsoleKeyInfo? key = null, object arg = nul
699699
/// </summary>
700700
public static void ScrollDisplayToCursor(ConsoleKeyInfo? key = null, object arg = null)
701701
{
702-
var newTop = Console.CursorTop;
702+
// Ideally, we'll put the last input line at the bottom of the window
703+
var coordinates = _singleton.ConvertOffsetToCoordinates(_singleton._buffer.Length);
704+
705+
var newTop = coordinates.Y - Console.WindowHeight + 1;
706+
707+
// But if the cursor won't be visible, make sure it is.
708+
if (newTop > Console.CursorTop)
709+
{
710+
// Add 10 for some extra context instead of putting the
711+
// cursor on the bottom line.
712+
newTop = Console.CursorTop - Console.WindowHeight + 10;
713+
}
714+
715+
// But we can't go past the end of the buffer.
703716
if (newTop > (Console.BufferHeight - Console.WindowHeight))
704717
{
705718
newTop = (Console.BufferHeight - Console.WindowHeight);

0 commit comments

Comments
 (0)