From d31123fa1d68c8da39e4f0c394b935fefe4e4a6d Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Wed, 10 May 2023 23:56:27 +0200 Subject: textinput: align completion popover Align the completion popover with the actual completion location on the textinput line. Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/ui/textinput.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index 65570e8b..d76e9349 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -151,7 +151,16 @@ func (ti *TextInput) drawPopover(ctx *Context) { } width := maxLen(ti.completions) + 3 height := len(ti.completions) - ctx.Popover(0, 0, width, height, cmp) + + pos := len(ti.prefix) - ti.scroll + if pos+width > ctx.Width() { + pos = ctx.Width() - width + } + if pos < 0 { + pos = 0 + } + + ctx.Popover(pos, 0, width, height, cmp) } func (ti *TextInput) MouseEvent(localX int, localY int, event tcell.Event) { -- cgit v1.2.3-54-g00ecf