Skip to content

Commit

Permalink
Don't SetCursorPosition when not Rendered.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msftrncs committed Nov 1, 2019
1 parent 65be868 commit 78c539e
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions PSReadLine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class RenderData
};
private int _initialX;
private int _initialY;
private bool _waitingToRender;

private ConsoleColor _initialForeground;
private ConsoleColor _initialBackground;
Expand Down Expand Up @@ -112,6 +113,7 @@ private void Render()
_tokens = null;
_ast = null;
_parseErrors = null;
_waitingToRender = true;
return;
}

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

_lastRenderTime.Restart();
_waitingToRender = false;
}

private static string Spaces(int cnt)
Expand Down Expand Up @@ -980,19 +983,24 @@ private void RecomputeInitialCoords()

private void MoveCursor(int newCursor)
{
// In case the buffer was resized
RecomputeInitialCoords();
_previousRender.bufferWidth = _console.BufferWidth;
_previousRender.bufferHeight = _console.BufferHeight;

var point = ConvertOffsetToPoint(newCursor);
if (point.Y < 0)
// Only update screen cursor if the buffer is fully rendered.
if (!_waitingToRender)
{
Ding();
return;
// In case the buffer was resized
RecomputeInitialCoords();
_previousRender.bufferWidth = _console.BufferWidth;
_previousRender.bufferHeight = _console.BufferHeight;

var point = ConvertOffsetToPoint(newCursor);
if (point.Y < 0)
{
Ding();
return;
}

_console.SetCursorPosition(point.X, point.Y);
}

_console.SetCursorPosition(point.X, point.Y);
_current = newCursor;
}

Expand Down

0 comments on commit 78c539e

Please sign in to comment.