mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08: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:
@ -57,7 +57,7 @@ namespace Spectre.Console.Internal
|
||||
return;
|
||||
}
|
||||
|
||||
var width = Segment.CellLength(context, segments);
|
||||
var width = Segment.CellCount(context, segments);
|
||||
if (width >= maxWidth)
|
||||
{
|
||||
return;
|
||||
|
@ -16,6 +16,11 @@ namespace Spectre.Console.Internal
|
||||
|
||||
public static int CellLength(this string text, RenderContext context)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
return Cell.GetCellLength(context, text);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,17 @@ namespace Spectre.Console.Internal
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We need to figure out why Segment.SplitLines fails
|
||||
// if we let wcwidth (which returns -1 instead of 1)
|
||||
// calculate the size for new line characters.
|
||||
// That is correct from a Unicode perspective, but the
|
||||
// algorithm was written before wcwidth was added and used
|
||||
// to work with string length and not cell length.
|
||||
if (rune == '\n')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return UnicodeCalculator.GetWidth(rune);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user