From 345ac41fe05f577e26cf552ce7b2c303fb10aec8 Mon Sep 17 00:00:00 2001 From: Jianyun Tao Date: Wed, 30 May 2018 14:15:55 -0700 Subject: [PATCH] Fixed cursor position after resize --- PSReadLine/ReadLine.cs | 1 + PSReadLine/Render.cs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 134a45fa..60fb2cc1 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -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(); diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 7b232da7..fc919dd5 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -36,6 +36,7 @@ struct RenderedLineData class RenderData { public int bufferWidth; + public int bufferHeight; public bool errorPrompt; public RenderedLineData[] lines; } @@ -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; @@ -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. @@ -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);