From b28f4ced49e4ce5c76446a9ee3e3fcd90adac744 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 4 Feb 2026 17:07:11 -0300 Subject: [PATCH] fix(ui): completions popup gets too narrow on single item (#2125) Signed-off-by: Carlos Alexandro Becker --- internal/ui/completions/completions.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/internal/ui/completions/completions.go b/internal/ui/completions/completions.go index 66389e3b99c09123334c1685bd8e22e4d7354ed1..a23ba5bf181f00856082b17aed8ef1ba5a816e93 100644 --- a/internal/ui/completions/completions.go +++ b/internal/ui/completions/completions.go @@ -128,16 +128,7 @@ func (c *Completions) SetFiles(files []string) { c.list.SelectFirst() c.list.ScrollToSelected() - // recalculate width by using just the visible items - start, end := c.list.VisibleItemIndices() - width := 0 - if end != 0 { - for _, file := range files[start : end+1] { - width = max(width, ansi.StringWidth(file)) - } - } - c.width = ordered.Clamp(width+2, int(minWidth), int(maxWidth)) - c.list.SetSize(c.width, c.height) + c.updateSize() } // Close closes the completions popup. @@ -158,14 +149,17 @@ func (c *Completions) Filter(query string) { c.query = query c.list.SetFilter(query) - // recalculate width by using just the visible items + c.updateSize() +} + +func (c *Completions) updateSize() { items := c.list.FilteredItems() start, end := c.list.VisibleItemIndices() width := 0 - if end != 0 { - for _, item := range items[start : end+1] { - width = max(width, ansi.StringWidth(item.(interface{ Text() string }).Text())) - } + for i := start; i <= end; i++ { + item := c.list.ItemAt(i) + s := item.(interface{ Text() string }).Text() + width = max(width, ansi.StringWidth(s)) } c.width = ordered.Clamp(width+2, int(minWidth), int(maxWidth)) c.height = ordered.Clamp(len(items), int(minHeight), int(maxHeight))