Skip to content

Commit 78c539e

Browse files
committed
Don't SetCursorPosition when not Rendered.
Block the setting of the console cursor when the buffer hasn't been completely rendered due to an input queue waiting to be processed. Fixes #1081.
1 parent 65be868 commit 78c539e

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

PSReadLine/Render.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class RenderData
6161
};
6262
private int _initialX;
6363
private int _initialY;
64+
private bool _waitingToRender;
6465

6566
private ConsoleColor _initialForeground;
6667
private ConsoleColor _initialBackground;
@@ -112,6 +113,7 @@ private void Render()
112113
_tokens = null;
113114
_ast = null;
114115
_parseErrors = null;
116+
_waitingToRender = true;
115117
return;
116118
}
117119

@@ -816,6 +818,7 @@ void UpdateColorsIfNecessary(string newColor)
816818
// TODO: set WindowTop if necessary
817819

818820
_lastRenderTime.Restart();
821+
_waitingToRender = false;
819822
}
820823

821824
private static string Spaces(int cnt)
@@ -980,19 +983,24 @@ private void RecomputeInitialCoords()
980983

981984
private void MoveCursor(int newCursor)
982985
{
983-
// In case the buffer was resized
984-
RecomputeInitialCoords();
985-
_previousRender.bufferWidth = _console.BufferWidth;
986-
_previousRender.bufferHeight = _console.BufferHeight;
987-
988-
var point = ConvertOffsetToPoint(newCursor);
989-
if (point.Y < 0)
986+
// Only update screen cursor if the buffer is fully rendered.
987+
if (!_waitingToRender)
990988
{
991-
Ding();
992-
return;
989+
// In case the buffer was resized
990+
RecomputeInitialCoords();
991+
_previousRender.bufferWidth = _console.BufferWidth;
992+
_previousRender.bufferHeight = _console.BufferHeight;
993+
994+
var point = ConvertOffsetToPoint(newCursor);
995+
if (point.Y < 0)
996+
{
997+
Ding();
998+
return;
999+
}
1000+
1001+
_console.SetCursorPosition(point.X, point.Y);
9931002
}
9941003

995-
_console.SetCursorPosition(point.X, point.Y);
9961004
_current = newCursor;
9971005
}
9981006

0 commit comments

Comments
 (0)