Skip to content

Commit b83522b

Browse files
jianyuntlzybkr
authored andcommitted
Fixed cursor position after resize (#694)
Add tracking of buffer height to recalculate initial coordinates. Fix #682
1 parent 9ca0326 commit b83522b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

PSReadLine/ReadLine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
586586

587587
_previousRender = _initialPrevRender;
588588
_previousRender.bufferWidth = _console.BufferWidth;
589+
_previousRender.bufferHeight = _console.BufferHeight;
589590
_previousRender.errorPrompt = false;
590591
_buffer.Clear();
591592
_edits = new List<EditItem>();

PSReadLine/Render.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct RenderedLineData
3636
class RenderData
3737
{
3838
public int bufferWidth;
39+
public int bufferHeight;
3940
public bool errorPrompt;
4041
public RenderedLineData[] lines;
4142
}
@@ -351,10 +352,12 @@ void UpdateColorsIfNecessary(string newColor)
351352
// TODO: avoid writing everything.
352353

353354
var bufferWidth = _console.BufferWidth;
355+
var bufferHeight = _console.BufferHeight;
354356

355357
// In case the buffer was resized
356358
RecomputeInitialCoords();
357359
renderData.bufferWidth = bufferWidth;
360+
renderData.bufferHeight = bufferHeight;
358361

359362
// Move the cursor to where we started, but make cursor invisible while we're rendering.
360363
_console.CursorVisible = false;
@@ -641,7 +644,8 @@ private void GetRegion(out int start, out int length)
641644

642645
private void RecomputeInitialCoords()
643646
{
644-
if (_previousRender.bufferWidth != _console.BufferWidth)
647+
if ((_previousRender.bufferWidth != _console.BufferWidth)
648+
|| (_previousRender.bufferHeight != _console.BufferHeight))
645649
{
646650
// If the buffer width changed, our initial coordinates
647651
// may have as well.
@@ -673,6 +677,7 @@ private void MoveCursor(int newCursor)
673677
// In case the buffer was resized
674678
RecomputeInitialCoords();
675679
_previousRender.bufferWidth = _console.BufferWidth;
680+
_previousRender.bufferHeight = _console.BufferHeight;
676681

677682
var point = ConvertOffsetToPoint(newCursor);
678683
PlaceCursor(point.X, point.Y);

0 commit comments

Comments
 (0)