diff --git a/cli/internal/tui/chat.go b/cli/internal/tui/chat.go index 0dd802a9..9aff08cb 100644 --- a/cli/internal/tui/chat.go +++ b/cli/internal/tui/chat.go @@ -540,14 +540,18 @@ func (m *ChatModel) SetSize(width, height int) { } m.Viewport.Width = transcriptWidth - m.Renderer.BodyWidth = min(100, available) m.TextArea.SetWidth(available) m.TextArea.SetHeight(m.maxPromptHeight()) m.RecoveryInput.Width = max(1, available-16) m.Viewport.Height = max(1, height-6-m.chromeRows()) - m.rebuildSettledLines() + // settled rows are rendered at the body width alone, so only a new body + // width renders them again + if body := min(100, available); body != m.Renderer.BodyWidth { + m.Renderer.BodyWidth = body + m.rebuildSettledLines() + } m.refreshViewportContent() } diff --git a/cli/internal/tui/glance_test.go b/cli/internal/tui/glance_test.go index 02c69222..5bb0973b 100644 --- a/cli/internal/tui/glance_test.go +++ b/cli/internal/tui/glance_test.go @@ -17,3 +17,23 @@ func TestWorkGlanceShowsStableItemIDBesidePendingCount(t *testing.T) { t.Fatalf("glance count should not be confused with item ID: %q", glance) } } + +// The glance poll and chrome changes resize the chat without changing its body +// width, and must not render the whole transcript again. +func TestResizeRendersTranscriptOnlyForNewBodyWidth(t *testing.T) { + m := NewChatModel(&daemon.Session{ID: "s"}, nil) + m.SetSize(140, 24) + m.appendSettledEntry(HistoryEntry{Kind: EntryAssistant, Speaker: "albedo", Text: "hello"}) + const kept = "rendered once" + m.settledLines[0] = kept + + m.Glances = []PageGlance{{Title: "pending work", Rows: []PageRow{{ID: "1", Text: "x"}}}} + m.SetSize(140, 30) + if m.settledLines[0] != kept { + t.Fatal("a resize keeping the body width rendered the transcript again") + } + m.SetSize(80, 30) + if m.settledLines[0] == kept { + t.Fatal("a narrower body should render the transcript again") + } +}