diff --git a/internal/ui/block_contract_test.go b/internal/ui/block_contract_test.go index b85d4dae..e921adcd 100644 --- a/internal/ui/block_contract_test.go +++ b/internal/ui/block_contract_test.go @@ -348,6 +348,32 @@ func TestBlockFitsWidth(t *testing.T) { } } +// TestBlockKeepsPromisedWidth pins the other side of the width contract. +// Widgets and extension blocks get widgetContentWidth for their content, and +// a line of that width must pass through the block unwrapped. A block that +// wraps it moves the last character onto a new line, and every line of a +// fitted markdown table breaks. +func TestBlockKeepsPromisedWidth(t *testing.T) { + for _, w := range widths { + for _, noBorder := range []bool{false, true} { + name := "border/w" + itoa(w) + opts := []renderingOption{WithAlign(lipgloss.Left)} + if noBorder { + name = "noborder/w" + itoa(w) + opts = append(opts, WithNoBorder()) + } + t.Run(name, func(t *testing.T) { + line := strings.Repeat("x", widgetContentWidth(w, noBorder)) + got := visibleLines(renderContentBlock(line, w, opts...)) + if len(got) != 1 { + t.Errorf("line of %d columns wrapped into %d lines:\n%s", + len(line), len(got), strings.Join(got, "\n")) + } + }) + } + } +} + // TestBlockTextColumn pins the left edge: a marker in column 0, text at // ContentOffset. A block that starts anywhere else makes the whole column // look ragged even when it is internally consistent. diff --git a/internal/ui/block_renderer.go b/internal/ui/block_renderer.go index 9760ca1a..de118242 100644 --- a/internal/ui/block_renderer.go +++ b/internal/ui/block_renderer.go @@ -121,7 +121,6 @@ func renderContentBlock(content string, containerWidth int, options ...rendering // Resolve border configuration. hasBorder := !renderer.noBorder - borderChars := 0 borderAlign := lipgloss.Left if renderer.align != nil { @@ -133,10 +132,6 @@ func renderContentBlock(content string, containerWidth int, options ...rendering borderColor = *renderer.borderColor } - if hasBorder { - borderChars = 1 - } - theme := style.GetTheme() // Resolve foreground color: caller override or theme default. @@ -176,7 +171,10 @@ func renderContentBlock(content string, containerWidth int, options ...rendering } if renderer.fullWidth { - blockStyle = blockStyle.Width(renderer.width - borderChars) + // lipgloss v2 counts the border as part of Width. The full + // container width leaves exactly widgetContentWidth columns for + // the text, with or without the border. + blockStyle = blockStyle.Width(renderer.width) } content = blockStyle.Render(content)