Skip to content

Fixed cursor position after resize #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)

_previousRender = _initialPrevRender;
_previousRender.bufferWidth = _console.BufferWidth;
_previousRender.bufferHeight = _console.BufferHeight;
_previousRender.errorPrompt = false;
_buffer.Clear();
_edits = new List<EditItem>();
Expand Down
7 changes: 6 additions & 1 deletion PSReadLine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct RenderedLineData
class RenderData
{
public int bufferWidth;
public int bufferHeight;
public bool errorPrompt;
public RenderedLineData[] lines;
}
Expand Down Expand Up @@ -351,10 +352,12 @@ void UpdateColorsIfNecessary(string newColor)
// TODO: avoid writing everything.

var bufferWidth = _console.BufferWidth;
var bufferHeight = _console.BufferHeight;

// In case the buffer was resized
RecomputeInitialCoords();
renderData.bufferWidth = bufferWidth;
renderData.bufferHeight = bufferHeight;

// Move the cursor to where we started, but make cursor invisible while we're rendering.
_console.CursorVisible = false;
Expand Down Expand Up @@ -633,7 +636,8 @@ private void GetRegion(out int start, out int length)

private void RecomputeInitialCoords()
{
if (_previousRender.bufferWidth != _console.BufferWidth)
if ((_previousRender.bufferWidth != _console.BufferWidth)
|| (_previousRender.bufferHeight != _console.BufferHeight))
{
// If the buffer width changed, our initial coordinates
// may have as well.
Expand Down Expand Up @@ -665,6 +669,7 @@ private void MoveCursor(int newCursor)
// In case the buffer was resized
RecomputeInitialCoords();
_previousRender.bufferWidth = _console.BufferWidth;
_previousRender.bufferHeight = _console.BufferHeight;

var point = ConvertOffsetToPoint(newCursor);
PlaceCursor(point.X, point.Y);
Expand Down