on main help sign in
fix(ui): completions popup gets too narrow on single item (#2125)
b28f4ceCarlos Alexandro Becker
internal/ui/completions/completions.go+9−15
@@ -128,16 +128,7 @@ func (c *Completions) SetFiles(files []string) {
128 c.list.SelectFirst()
128 c.list.SelectFirst()
129 c.list.ScrollToSelected()
129 c.list.ScrollToSelected()
130
130
131− // recalculate width by using just the visible items
131+ c.updateSize()
132− start, end := c.list.VisibleItemIndices()
133− width := 0
134− if end != 0 {
135− for _, file := range files[start : end+1] {
136− width = max(width, ansi.StringWidth(file))
137− }
138− }
139− c.width = ordered.Clamp(width+2, int(minWidth), int(maxWidth))
140− c.list.SetSize(c.width, c.height)
141}
132}
142
133
143// Close closes the completions popup.
134// Close closes the completions popup.
@@ -158,14 +149,17 @@ func (c *Completions) Filter(query string) {
158 c.query = query
149 c.query = query
159 c.list.SetFilter(query)
150 c.list.SetFilter(query)
160
151
161− // recalculate width by using just the visible items
152+ c.updateSize()
153+}
154+
155+func (c *Completions) updateSize() {
162 items := c.list.FilteredItems()
156 items := c.list.FilteredItems()
163 start, end := c.list.VisibleItemIndices()
157 start, end := c.list.VisibleItemIndices()
164 width := 0
158 width := 0
165− if end != 0 {
166− for _, item := range items[start : end+1] {
159+ for i := start; i <= end; i++ {
160+ item := c.list.ItemAt(i)
161+ s := item.(interface{ Text() string }).Text()
167− width = max(width, ansi.StringWidth(item.(interface{ Text() string }).Text()))
162+ width = max(width, ansi.StringWidth(s))
168− }
169 }
163 }
170 c.width = ordered.Clamp(width+2, int(minWidth), int(maxWidth))
164 c.width = ordered.Clamp(width+2, int(minWidth), int(maxWidth))
171 c.height = ordered.Clamp(len(items), int(minHeight), int(maxHeight))
165 c.height = ordered.Clamp(len(items), int(minHeight), int(maxHeight))