Skip to content

Fix TUI Column gap off-by-one and Empty children taking a slot - #36

Merged
archlemon merged 1 commit into
mainfrom
fix/tui-gap-empty
Nov 28, 2026
Merged

archlemon merged 1 commit into
mainfrom
fix/tui-gap-empty

Conversation

@archlemon

Copy link
Copy Markdown
Member

Summary

Fixes #35. Both claims are confirmed with the repro from the issue, plus a few related cases the probe turned up.

1. Column gap off by one. renderBox joined a gap part of Gap newlines, and lipgloss.JoinVertical draws that as Gap+1 lines. The gap part is now Gap-1 newlines.

main this PR
Column, Gap: 1, a, b "a\n \n \nb" "a\n \nb"
Column, Gap: 2, a, b 3 blank lines 2
collapsed Wrap Row, Gap: 2 3 blank lines between panes 2

Related: distributeColumn budgets Gap*(n-1) lines for gaps, so a Fill-height Column with a gap overflowed its height by one line per gap. With the drawing fixed, it fits.

2. Empty children took a slot. Empty() (and When(false, …), If(false, …), nil, Keyed(k, Empty())) rendered as "" and still got a line plus a gap on each side. Beyond what the issue lists, this also happened:

  • in a Column with no gap: "a\n \nb";
  • in Rows: Row, Gap: 1, a, Empty, b gave "a b".

In the browser an empty comment node is not a flex item and takes no gap. renderBox now lays out only non-empty children (laidOutChildren). Grow, Wrap and distribution all use the filtered list, and focus collection was already unaffected.

Also guarded the gap join for fewer than two parts, which would have panicked on a Box whose children are all empty.

Browser side

The issue says the browser already gets this right. New e2e test TestColumnGapIsOneLineAndSkipsEmpty confirms it: a Gap: 1 column leaves exactly one line between items in Chromium, and a hidden When between them adds no space.

Test plan

  • New gap_test.go: the gap counts, hidden When, gap-0 Empty, keyed Empty, Row with Empty, leading and trailing Empty, all-Empty children, collapsed wrap gap, and Fill-height column with a gap. All fail on main.
  • New e2e browser parity test
  • go test -race ./..., make e2e, both vets

Known remaining difference: a multi-variant Responsive whose visible variant is Empty still takes a slot in both renderers. The browser keeps its wrapper div as a zero-height flex item, so the two differ by that one line. Left as is; it needs a browser-side change too.

A Column's gap was joined as a part of Gap newlines, which
lipgloss.JoinVertical draws as Gap+1 lines, so every gapped Column
(and every collapsed wrapping Row) had one blank line too many per gap.
Fill-height columns budgeted Gap lines per gap, so they also overflowed
their height. The gap part is now Gap-1 newlines.

Empty children (When(false, ...), If(false, ...), nil, Keyed Empty)
were laid out as a blank slot with a gap on each side, in Columns and
Rows alike, while in the browser an empty comment node is not a flex
item and takes no gap. Boxes now lay out only their non-empty children.

Closes #35
@archlemon
archlemon merged commit 088542e into main Nov 28, 2026
2 checks passed
@archlemon
archlemon deleted the fix/tui-gap-empty branch November 28, 2026 10:38
archlemon added a commit that referenced this pull request Nov 28, 2026
Following the Empty fix in #36, a Responsive whose visible variant is
Empty still took a slot: in the TUI a blank line plus a gap on each
side, in the browser a zero-height wrapper with a gap on each side.

TUI: a Box drops children whose Responsive picks an empty variant at
the width they were given (after rendering them, so their picks stay
recorded for the focus ring), re-checking after a wrap collapse.

Browser: the wrapper must stay a box for its container queries, and
those cannot style the wrapper itself. In a gapped Column, a Responsive
with an Empty variant now carries a per-instance rule that cancels one
gap with a negative end margin while the wrapper is flagged empty, and
the renderer keeps the flag current with a ResizeObserver, which runs
after layout and before paint.

In a Row the browser wrapper still reserves its widest breakpoint's
width; that existing limitation is now documented in the README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: Column Gap draws one extra blank line, and Empty() children take up a slot

1 participant