Fix rendering bug when splitting lines

The bug might occur if there are wide characters such as emojis
at the end of a line. The SplitLines method mixed cell width
and text length, which might give incorrect results. This commit
makes sure that comparison and calculation is done using cell width
where it's appropriate.
This commit is contained in:
Patrik Svensson
2020-10-24 01:45:41 +02:00
parent 041bd016a2
commit c9c0ad733f
11 changed files with 197 additions and 57 deletions

View File

@ -94,7 +94,7 @@ namespace Spectre.Console
// Split the child segments into lines.
var childSegments = ((IRenderable)child).Render(context, childWidth);
foreach (var line in Segment.SplitLines(childSegments, childWidth))
foreach (var line in Segment.SplitLines(context, childSegments, childWidth))
{
if (line.Count == 1 && line[0].IsWhiteSpace)
{
@ -109,7 +109,7 @@ namespace Spectre.Console
content.AddRange(line);
// Do we need to pad the panel?
var length = line.Sum(segment => segment.CellLength(context));
var length = line.Sum(segment => segment.CellCount(context));
if (length < childWidth)
{
var diff = childWidth - length;
@ -148,7 +148,7 @@ namespace Spectre.Console
var headerWidth = panelWidth - (EdgeWidth * 2);
var header = Segment.TruncateWithEllipsis(Header.Text, Header.Style ?? borderStyle, context, headerWidth);
var excessWidth = headerWidth - header.CellLength(context);
var excessWidth = headerWidth - header.CellCount(context);
if (excessWidth > 0)
{
switch (Header.Alignment ?? Justify.Left)