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
26 changes: 26 additions & 0 deletions internal/ui/block_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 4 additions & 6 deletions internal/ui/block_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading