diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index f427fb3..af22ab1 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -760,11 +760,22 @@ namespace Microsoft.PowerShell } // Fewer logical lines than our previous render? Clear them. - for (; previousLogicalLine < previousRenderLines.Length; previousLogicalLine++) + for (int line = previousLogicalLine; line < previousRenderLines.Length; line++) { + if (line > previousLogicalLine || logicalLineStartIndex < renderLines.Length) + { + // For the first of the remaining previous logical lines, if we didn't actually + // render anything for the current logical lines, then the cursor is already at + // the beginning of the right physical line that should be cleared, and thus no + // need to write a new line in such case. + // In other cases, we need to write a new line to get the cursor to the correct + // physical line. + + _console.Write("\n"); + } + // No need to write new line if all we need is to clear the extra previous render. - if (logicalLineStartIndex < renderLines.Length) { _console.Write("\n"); } - _console.Write(Spaces(previousRenderLines[previousLogicalLine].columns)); + _console.Write(Spaces(previousRenderLines[line].columns)); } // Preserve the current render data.