Skip to content

Commit 3329c99

Browse files
authored
Merge pull request #1598 from krissetto/dont-go-negative-tui-dimentions
Don't go negative in tui dimensions in collapsed sidebar
2 parents 4e6da79 + c9abaa8 commit 3329c99

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

pkg/tui/page/chat/chat.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,13 @@ const pendingSpinnerHeight = 3
604604

605605
// renderCollapsedSidebar renders the sidebar in collapsed mode (at top of screen).
606606
func (p *chatPage) renderCollapsedSidebar(sl sidebarLayout) string {
607+
// Guard against unset/invalid layout (can happen before WindowSizeMsg is received).
608+
width := max(0, sl.innerWidth)
609+
height := max(0, sl.sidebarHeight)
610+
if width == 0 || height == 0 {
611+
return ""
612+
}
613+
607614
sidebarView := p.sidebar.View()
608615
sidebarLines := strings.Split(sidebarView, "\n")
609616

@@ -614,18 +621,18 @@ func (p *chatPage) renderCollapsedSidebar(sl sidebarLayout) string {
614621
}
615622

616623
// Replace the last line with a subtle divider
617-
divider := styles.FadingStyle.Render(strings.Repeat("─", sl.innerWidth))
618-
if len(sidebarLines) >= sl.sidebarHeight {
619-
sidebarLines[sl.sidebarHeight-1] = divider
624+
divider := styles.FadingStyle.Render(strings.Repeat("─", width))
625+
if len(sidebarLines) >= height {
626+
sidebarLines[height-1] = divider
620627
} else {
621628
sidebarLines = append(sidebarLines, divider)
622629
}
623630

624631
sidebarWithDivider := strings.Join(sidebarLines, "\n")
625632

626633
return lipgloss.NewStyle().
627-
Width(sl.innerWidth).
628-
Height(sl.sidebarHeight).
634+
Width(width).
635+
Height(height).
629636
Align(lipgloss.Left, lipgloss.Top).
630637
Render(sidebarWithDivider)
631638
}

0 commit comments

Comments
 (0)