mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2026-01-02 01:03:32 +01:00
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:
@@ -217,7 +217,7 @@ namespace Spectre.Console
|
||||
var justification = _columns[columnIndex].Alignment;
|
||||
var childContext = context.WithJustification(justification);
|
||||
|
||||
var lines = Segment.SplitLines(cell.Render(childContext, rowWidth));
|
||||
var lines = Segment.SplitLines(context, cell.Render(childContext, rowWidth));
|
||||
cellHeight = Math.Max(cellHeight, lines.Count);
|
||||
cells.Add(lines);
|
||||
}
|
||||
@@ -261,7 +261,7 @@ namespace Spectre.Console
|
||||
rowResult.AddRange(cell[cellRowIndex]);
|
||||
|
||||
// Pad cell content right
|
||||
var length = cell[cellRowIndex].Sum(segment => segment.CellLength(context));
|
||||
var length = cell[cellRowIndex].Sum(segment => segment.CellCount(context));
|
||||
if (length < columnWidths[cellIndex])
|
||||
{
|
||||
rowResult.Add(new Segment(new string(' ', columnWidths[cellIndex] - length)));
|
||||
@@ -295,7 +295,7 @@ namespace Spectre.Console
|
||||
Aligner.Align(context, rowResult, Alignment, actualMaxWidth);
|
||||
|
||||
// Is the row larger than the allowed max width?
|
||||
if (Segment.CellLength(context, rowResult) > actualMaxWidth)
|
||||
if (Segment.CellCount(context, rowResult) > actualMaxWidth)
|
||||
{
|
||||
result.AddRange(Segment.Truncate(context, rowResult, actualMaxWidth));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user