Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 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,37 +983,44 @@ 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;

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;
var point = ConvertOffsetToPoint(newCursor);
if (point.Y < 0)
{
Ding();
return;
}

// 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);
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;

// Scroll up the buffer by 1 line.
_console.Write("\n");
}
else
{
_console.SetCursorPosition(point.X, point.Y);
// 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);
}
}

// While waiting to render, and a keybinding has occured that is moving the cursor,
// converting offset to point could potentially result in an invalid screen position,
// but the insertion point should reflect the move.
_current = newCursor;
}

Expand Down