Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- A screen reader hears one row of a fixed-width table as one line. `BlockLayout.Relayout` with
`LayoutContext.Linear` now wraps a block that is not fluid at the reader's width, as it does a fluid one;
before, it wrapped at the width the block's columns took, so a 35-cell WHO listing broke each player's row in two. The same holds for one nested in another block (`Bounded`).
- Two equal elements side by side stay two. Before, an element closed and an equal one opened straight after it
became one run, so a client saw one thing where the server sent two. This happened with two exits of one
flagged element (`<Exit>north</Exit><Exit>south</Exit>` read as one exit, `northsouth`), two `<SEND>`s, `<A>`s
Expand Down
27 changes: 27 additions & 0 deletions MarkupString.Tests/Layout/BlockLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,33 @@ await Assert.That(string.Join("\n", lines.Select(l => l.ToPlainText()))).IsEqual
"Origin: Super Robot Wars AG\nOnline: 1h, Idle: 0s\nFactions\nMEDJAI, Court of Stardust\nQuote\nHooooo?");
}

[Test]
public async Task Linear_ReadsAFixedWidthTableRowAsOneLineAtTheReadersWidth()
{
// A WHO listing is laid out at its own width (not fluid); read aloud, its one row is one line.
var table = new Table([new TableColumn(P("Player Name")) { Min = 16 }, new TableColumn(P("On For")) { Min = 10, Alignment = Alignment.Right }, new TableColumn(P("Idle ")) { Min = 7, Alignment = Alignment.Right }],
[[P("Marguerite"), P("7s"), P("0s")]])
{ Gap = 1 };
var text = BlockLayout.Build(table, 35);

var read = BlockLayout.Relayout(text, 78, new LayoutContext { Linear = true });

await Assert.That(read.ToPlainText()).IsEqualTo("Player Name: Marguerite, On For: 7s, Idle: 0s");
}

[Test]
public async Task Linear_ReadsANestedFixedWidthTableRowAsOneLine()
{
// The same listing nested in a fluid block keeps its own width (Bounded); read aloud, it still reads as one line.
var table = new Table([new TableColumn(P("Player Name")) { Min = 16 }, new TableColumn(P("On For")) { Min = 10, Alignment = Alignment.Right }],
[[P("Marguerite"), P("7s")]]);
var text = BlockLayout.Build(new Bounded(table, 20), 78, fluid: true);

var read = BlockLayout.Relayout(text, 78, new LayoutContext { Linear = true });

await Assert.That(read.ToPlainText()).IsEqualTo("Player Name: Marguerite, On For: 7s");
}

[Test]
public async Task Flex_StacksWhenItemsDoNotFit()
{
Expand Down
7 changes: 5 additions & 2 deletions MarkupString/Layout/Blocks/BlockLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private static void AddText(MarkupText content, int start, int end, Alignment? a

/// <summary>
/// <paramref name="text"/> with every intact block laid out again under <paramref name="context"/>:
/// a <see cref="LayoutMarkup.Fluid"/> block at <paramref name="width"/>, any other at its own width.
/// a <see cref="LayoutMarkup.Fluid"/> block at <paramref name="width"/>, and any block read in order
/// (<see cref="LayoutContext.Linear"/>) too; any other at its own width.
/// A block that was cut, edited or shares a line with other text is left as it is.
/// </summary>
/// <param name="text">The text.</param>
Expand All @@ -120,7 +121,9 @@ public static MarkupText Relayout(MarkupText text, int width, LayoutContext cont
foreach (var region in BlockRegions.Find(text))
{
if (region.Markup is not LayoutMarkup layout || !region.Intact || !region.Standalone) continue;
var target = layout.Fluid && width > 0 ? width : layout.Width;
// A screen reader hears a fixed-width block in reading order, so its lines wrap at the reader's
// width, not at the width its columns took: one row of a table stays one line.
var target = (layout.Fluid || context.Linear) && width > 0 ? width : layout.Width;
if (target == layout.Width && context == LayoutContext.Default) continue;
edits.Add((region.Start, region.End - region.Start, Build(layout.Root, target, layout.Fluid, context)));
}
Expand Down
5 changes: 5 additions & 0 deletions MarkupString/Layout/Blocks/Modifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public override Block MapText(Func<MarkupText, MarkupText> map) =>
public override void Draw(LayoutContext context, int width, IList<MarkupText> lines) =>
context.Draw(Content, Math.Min(width, Math.Max(1, Width)), lines);

/// <inheritdoc/>
/// <remarks>Read in order, its content wraps at the reader's width: the bound keeps columns, which a reader does not hear.</remarks>
public override void DrawLinear(LayoutContext context, int width, IList<MarkupText> lines) =>
context.Draw(Content, width, lines);

/// <inheritdoc/>
public override BlockMeasure Measure(LayoutContext context, int width)
{
Expand Down
1 change: 1 addition & 0 deletions MarkupString/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -877,3 +877,4 @@ override MarkupString.ElementMarkup.GetHashCode() -> int
override MarkupString.ElementMarkup.ToString() -> string!
static MarkupString.ElementMarkup.operator !=(MarkupString.ElementMarkup? left, MarkupString.ElementMarkup? right) -> bool
static MarkupString.ElementMarkup.operator ==(MarkupString.ElementMarkup? left, MarkupString.ElementMarkup? right) -> bool
override MarkupString.Layout.Bounded.DrawLinear(MarkupString.Layout.LayoutContext! context, int width, System.Collections.Generic.IList<MarkupString.MarkupText!>! lines) -> void
Loading