on main help sign in
fix(tui): completions: readjust position on filter change
6dc3cf2Ayman Bagabas
internal/tui/components/completions/completions.go+10−8
@@ -51,13 +51,14 @@ type Completions interface {
51}
51}
52
52
53type completionsCmp struct {
53type completionsCmp struct {
54− wWidth int // The window width
54+ wWidth int // The window width
55− width int
55+ width int
56+ lastWidth int
56− height int // Height of the completions component`
57+ height int // Height of the completions component`
57− x, xorig int // X position for the completions popup
58+ x, xorig int // X position for the completions popup
58− y int // Y position for the completions popup
59+ y int // Y position for the completions popup
59− open bool // Indicates if the completions are open
60+ open bool // Indicates if the completions are open
60− keyMap KeyMap
61+ keyMap KeyMap
61
62
62 list list.ListModel
63 list list.ListModel
63 query string // The current filter query
64 query string // The current filter query
@@ -210,7 +211,8 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
210 items := c.list.Items()
211 items := c.list.Items()
211 itemsLen := len(items)
212 itemsLen := len(items)
212 width := listWidth(items)
213 width := listWidth(items)
214+ c.lastWidth = c.width
213− if c.x < 0 {
215+ if c.x < 0 || width < c.lastWidth {
214 c.x = c.xorig
216 c.x = c.xorig
215 } else if c.x+width >= c.wWidth {
217 } else if c.x+width >= c.wWidth {
216 c.x = c.wWidth - width - 1
218 c.x = c.wWidth - width - 1