Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions PSReadLine/DynamicHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,14 @@ private class MultilineDisplayBlock : DisplayBlockBase
{
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;

this.SaveCursor();

Expand All @@ -261,16 +262,23 @@ public void DrawMultilineBlock()
{
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

extraPhysicalLines += extra;
}

console.Write(items[index]);

// Explicit newline so consoles see each row as distinct lines, but skip the
Expand All @@ -287,7 +295,7 @@ public void DrawMultilineBlock()

public void Clear()
{
_singleton.WriteBlankLines(Top, ItemsToDisplay.Count + multilineItems);
_singleton.WriteBlankLines(Top, ItemsToDisplay.Count + extraPhysicalLines);
}
}
}
Expand Down