Handle screen buffer scrolling correctly for inline dynamic help (#2951)

This commit is contained in:
Dongbo Wang
2021-11-04 15:44:16 -07:00
committed by GitHub
parent 81bf8669fd
commit e02b0da57a
+14 -6
View File
@@ -233,13 +233,14 @@ namespace Microsoft.PowerShell
{
internal Collection<string> ItemsToDisplay;
private int multilineItems = 0;
// Keep track of the number of extra physical lines due to multi-line text.
private int extraPhysicalLines = 0;
public void DrawMultilineBlock()
{
IConsole console = Singleton._console;
multilineItems = 0;
extraPhysicalLines = 0;
SaveCursor();
MoveCursorToStartDrawingPosition(console);
@@ -251,16 +252,23 @@ namespace Microsoft.PowerShell
{
var itemLength = LengthInBufferCells(items[index]);
int extra = 0;
if (itemLength > bufferWidth)
{
multilineItems += itemLength / bufferWidth;
extra = itemLength / bufferWidth;
if (itemLength % bufferWidth == 0)
{
multilineItems--;
extra--;
}
}
if (extra > 0)
{
// Extra physical lines may cause buffer to scroll up.
AdjustForPossibleScroll(extra);
extraPhysicalLines += extra;
}
console.Write(items[index]);
// Explicit newline so consoles see each row as distinct lines, but skip the
@@ -277,7 +285,7 @@ namespace Microsoft.PowerShell
public void Clear()
{
_singleton.WriteBlankLines(Top, ItemsToDisplay.Count + multilineItems);
_singleton.WriteBlankLines(Top, ItemsToDisplay.Count + extraPhysicalLines);
}
}
}