From 344878dcbbcd8e055096a741d14bfe4c8f5872d5 Mon Sep 17 00:00:00 2001 From: Jianyun Date: Wed, 1 Aug 2018 13:31:49 -0700 Subject: [PATCH] Set the cursor to the place where a user hits tab key (#7299) * Set the cursor to the place where a user hits tab key --- .../host/msh/ProgressPane.cs | 13 +++++++++---- .../engine/MshCommandRuntime.cs | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs index 3b6dab189d..d98f04861b 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs @@ -89,12 +89,17 @@ namespace Microsoft.PowerShell //if the cursor is at the bottom, create screen buffer space by scrolling int scrollRows = rows - ((_rawui.BufferSize.Height - 1) - _location.Y); - for (int i = 0; i < rows; i++) - { - Console.Out.Write('\n'); - } if (scrollRows > 0) { + // Scroll the console screen up by 'scrollRows' + var bottomLocation = _location; + bottomLocation.Y = _rawui.BufferSize.Height; + _rawui.CursorPosition = bottomLocation; + for (int i = 0; i < scrollRows; i++) + { + Console.Out.Write('\n'); + } + _location.Y -= scrollRows; _savedCursor.Y -= scrollRows; } diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index 923883890d..c24844be84 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -2252,7 +2252,7 @@ namespace System.Management.Automation { // Only generate these exceptions if a pipeline has already been declared as the 'writing' pipeline. // Otherwise, these are probably infrastructure messages and can be ignored. - if (this.PipelineProcessor._permittedToWrite != null) + if (this.PipelineProcessor?._permittedToWrite != null) { throw PSTraceSource.NewInvalidOperationException( PipelineStrings.WriteNotPermitted);