mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
Handle screen buffer scrolling correctly for inline dynamic help (#2951)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user