From 675d8515bfa37db9dd270f6d97faa494c650af2f Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 16 Dec 2025 17:12:07 -0500 Subject: [PATCH] fix(ui): adjust dialog sizing to account for dynamic title and help heights --- internal/ui/dialog/commands.go | 9 +++++++-- internal/ui/dialog/sessions.go | 11 ++++++++--- internal/ui/dialog/sessions_item.go | 10 +++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/internal/ui/dialog/commands.go b/internal/ui/dialog/commands.go index 763e20969df1c62849a4ee4907c95132f9c01ddb..1d45064a1a716ae1a6736a27a15c6c358b2e108e 100644 --- a/internal/ui/dialog/commands.go +++ b/internal/ui/dialog/commands.go @@ -111,11 +111,16 @@ func NewCommands(com *common.Common, sessionID string) (*Commands, error) { // SetSize sets the size of the dialog. func (c *Commands) SetSize(width, height int) { + t := c.com.Styles c.width = width c.height = height innerWidth := width - c.com.Styles.Dialog.View.GetHorizontalFrameSize() - c.input.SetWidth(innerWidth - c.com.Styles.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) - c.list.SetSize(innerWidth, height-6) // (1) title + (3) input + (1) padding + (1) help + heightOffset := t.Dialog.Title.GetVerticalFrameSize() + 1 + // (1) title content + t.Dialog.InputPrompt.GetVerticalFrameSize() + 1 + // (1) input content + t.Dialog.HelpView.GetVerticalFrameSize() + + t.Dialog.View.GetVerticalFrameSize() + c.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding + c.list.SetSize(innerWidth, height-heightOffset) c.help.SetWidth(width) } diff --git a/internal/ui/dialog/sessions.go b/internal/ui/dialog/sessions.go index 933547c5665b292f9cb7a125424803f219bbf706..bfc107ab40225aa33ad8f3520ef818020ac90f4a 100644 --- a/internal/ui/dialog/sessions.go +++ b/internal/ui/dialog/sessions.go @@ -67,11 +67,16 @@ func NewSessions(com *common.Common, sessions ...session.Session) *Session { // SetSize sets the size of the dialog. func (s *Session) SetSize(width, height int) { + t := s.com.Styles s.width = width s.height = height - innerWidth := width - s.com.Styles.Dialog.View.GetHorizontalFrameSize() - s.input.SetWidth(innerWidth - s.com.Styles.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) - s.list.SetSize(innerWidth, height-6) // (1) title + (3) input + (1) padding + (1) help + innerWidth := width - t.Dialog.View.GetHorizontalFrameSize() + heightOffset := t.Dialog.Title.GetVerticalFrameSize() + 1 + // (1) title content + t.Dialog.InputPrompt.GetVerticalFrameSize() + 1 + // (1) input content + t.Dialog.HelpView.GetVerticalFrameSize() + + t.Dialog.View.GetVerticalFrameSize() + s.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding + s.list.SetSize(innerWidth, height-heightOffset) s.help.SetWidth(width) } diff --git a/internal/ui/dialog/sessions_item.go b/internal/ui/dialog/sessions_item.go index dbfd939c93530dad95e2f25bce543d9a33f39f5e..ddd46c94be32ba885963d17f74efd4d8759a96c1 100644 --- a/internal/ui/dialog/sessions_item.go +++ b/internal/ui/dialog/sessions_item.go @@ -84,11 +84,15 @@ func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, w age = " " + age } - ageLen := lipgloss.Width(age) - titleLen := lipgloss.Width(title) + + var ageLen int + if updatedAt > 0 { + ageLen = lipgloss.Width(age) + } + title = ansi.Truncate(title, max(0, width-ageLen), "…") + titleLen := lipgloss.Width(title) right := lipgloss.NewStyle().AlignHorizontal(lipgloss.Right).Width(width - titleLen).Render(age) - content := title if matches := len(m.MatchedIndexes); matches > 0 { var lastPos int