fix(ui): adjust dialog sizing to account for dynamic title and help heights

Ayman Bagabas created

Change summary

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(-)

Detailed changes

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)
 }
 

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)
 }
 

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