diff --git a/CHANGELOG.md b/CHANGELOG.md index ca6d7ed..a338c67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ All notable changes to `MarkupString`, `MarkupString.Ansi`, `MarkupString.Html`, 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). +## Unreleased + +### Fixed + +- In HTML, an item of a `Flex` row with a set width keeps that width beside an item with none, as a + terminal draws it: the spare width goes to the item with none. A two-cell marker beside a reply took + half the row and pushed the reply to the right. + ## 2.31.0 — 2026-11-12 ### Added diff --git a/MarkupString.Html/Emitters/LayoutHtml.cs b/MarkupString.Html/Emitters/LayoutHtml.cs index fee5acc..5d63776 100644 --- a/MarkupString.Html/Emitters/LayoutHtml.cs +++ b/MarkupString.Html/Emitters/LayoutHtml.cs @@ -228,15 +228,19 @@ private static void Flex(Flex flex, HtmlLayoutWriter html, BorderStyle? frame) } html.Write("\">"); + // As in a terminal, a row with an item of no set width gives all its spare width to those items. + var hasAuto = items.Any(block => Layout.Flex.SizeOf(block).Basis.Kind == BlockSizeKind.Auto); foreach (var block in items) { // Each item asks for its terminal width and grows to fill its row, so items that do not fit // side by side wrap onto rows of their own. Spare width is left alone only when the layout // asked for it to be placed somewhere. var item = Layout.Flex.SizeOf(block); - // A Bounded item keeps its width, as in a terminal: the spare goes after it, not into it. - var grow = block is not Bounded && (flex.Justify == FlexJustify.Start || item.Basis.Kind == BlockSizeKind.Auto) - ? Math.Max(1, item.Grow) + // A Bounded item keeps its width, as in a terminal: the spare goes after it, not into it. So + // does an item with a set width beside one without: the spare goes to the one without. + var grow = item.Basis.Kind == BlockSizeKind.Auto ? Math.Max(1, item.Grow) + : hasAuto ? 0 + : block is not Bounded && flex.Justify == FlexJustify.Start ? Math.Max(1, item.Grow) : item.Grow; html.Write("