Minor refactors (#1081)

This commit is contained in:
Elisha Aguilera
2023-05-14 07:30:27 -07:00
committed by GitHub
parent 404b052a5f
commit 018f4ebd17
5 changed files with 13 additions and 27 deletions

View File

@@ -68,8 +68,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
foreach (var (_, first, last, part) in text.SplitLines().Enumerate())
{
var current = part;
if (first)
{
var line = _lines.LastOrDefault();
@@ -79,13 +77,13 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
line = _lines.Last();
}
if (string.IsNullOrEmpty(current))
if (string.IsNullOrEmpty(part))
{
line.Add(Segment.Empty);
}
else
{
foreach (var span in current.SplitWords())
foreach (var span in part.SplitWords())
{
line.Add(new Segment(span, style ?? Style.Plain));
}
@@ -95,13 +93,13 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
{
var line = new SegmentLine();
if (string.IsNullOrEmpty(current))
if (string.IsNullOrEmpty(part))
{
line.Add(Segment.Empty);
}
else
{
foreach (var span in current.SplitWords())
foreach (var span in part.SplitWords())
{
line.Add(new Segment(span, style ?? Style.Plain));
}
@@ -198,13 +196,11 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
var lines = new List<SegmentLine>();
var line = new SegmentLine();
var newLine = true;
using var iterator = new SegmentLineIterator(_lines);
var queue = new Queue<Segment>();
while (true)
{
var current = (Segment?)null;
Segment? current;
if (queue.Count == 0)
{
if (!iterator.MoveNext())
@@ -224,13 +220,12 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
throw new InvalidOperationException("Iterator returned empty segment.");
}
newLine = false;
var newLine = false;
if (current.IsLineBreak)
{
lines.Add(line);
line = new SegmentLine();
newLine = true;
continue;
}
@@ -246,7 +241,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
{
lines.Add(line);
line = new SegmentLine();
newLine = true;
segments.ForEach(s => queue.Enqueue(s));
continue;
@@ -276,8 +270,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
continue;
}
newLine = false;
line.Add(current);
}