From 6bde1e0325a3fd341989e5512c2a1b2437799ff6 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 17:18:21 +0000 Subject: [PATCH] Trim table headings used as card labels A heading padded to line its column up ("Idle ") read "Idle : 59s" to a screen reader and in narrow card layouts. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_015YDiaApsFRN4PnfRwGRp7i --- CHANGELOG.md | 8 ++++++++ MarkupString.Tests/Layout/FieldsAndTreeTests.cs | 10 ++++++++++ MarkupString/Layout/Blocks/Table.cs | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b8b511..521abb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and `MarkupString.Pueblo`. The packages share one version and are released toget The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.22.1 — Unreleased + +### Fixed + +- A `Table` read as cards (linear, or too narrow for its columns) trims the spaces around each heading + before using it as a label, so a heading padded for its column, such as `"Idle "`, reads `Idle: 59s` + instead of `Idle : 59s`. + ## 2.22.0 — Unreleased ### Added diff --git a/MarkupString.Tests/Layout/FieldsAndTreeTests.cs b/MarkupString.Tests/Layout/FieldsAndTreeTests.cs index 271361e..b8e8b85 100644 --- a/MarkupString.Tests/Layout/FieldsAndTreeTests.cs +++ b/MarkupString.Tests/Layout/FieldsAndTreeTests.cs @@ -94,6 +94,16 @@ public async Task Fields_Linear_ReadLabelThenValue() => await Assert.That(Lines(Sheet(Character[..2]) with { Columns = 2 }, 40, new LayoutContext { Linear = true })) .IsEquivalentTo(new[] { "Sex: Male", "Species: Human" }); + [Test] + public async Task Table_Linear_LabelsEachCellWithoutTheHeadingsPadding() + { + var table = new Table( + [new TableColumn(P("Player")), new TableColumn(P("Idle ")) { Alignment = Alignment.Right }], + [[new TextBlock(P("Mannaz")), new TextBlock(P("59s"))]]); + + await Assert.That(Lines(table, 40, new LayoutContext { Linear = true })).IsEquivalentTo(new[] { "Player: Mannaz", "Idle: 59s" }); + } + private static Tree Channels(TreeGuide guide) => new( [ new TreeItem(P("Channels"), diff --git a/MarkupString/Layout/Blocks/Table.cs b/MarkupString/Layout/Blocks/Table.cs index e3e333e..ad009b8 100644 --- a/MarkupString/Layout/Blocks/Table.cs +++ b/MarkupString/Layout/Blocks/Table.cs @@ -98,7 +98,8 @@ private void DrawCards(LayoutContext context, int width, IList lines { if (r > 0 && !context.Linear) lines.Add(MarkupText.Empty); var row = rows[r]; - cards.Draw(new Fields([.. Enumerable.Range(0, Columns.Length).Select(c => new Field(Columns[c].Header, Cell(row, c)))]), width, lines); + // A header's outer spaces line its column up with the next; as a label they would sit before the colon. + cards.Draw(new Fields([.. Enumerable.Range(0, Columns.Length).Select(c => new Field(Columns[c].Header.Trim(TrimType.TrimBoth), Cell(row, c)))]), width, lines); } }