From 8eb20fa690aac9be69e828063ab741d51c781cf6 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 15 Jul 2025 11:09:49 -0400 Subject: [PATCH 1/2] fix(tui): adjust completions popup to fit within window width This commit modifies the completions popup to reposition itself if it exceeds the window width and moves it to the right edge of the window. --- internal/tui/components/completions/completions.go | 14 +++++++++++++- internal/tui/tui.go | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index 5a6bcfe92e23f38c3f40c84770a0dcc9893e59d5..1b3a09bc6b1a5d49fb8b10a9e19261da50742892 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -40,6 +40,8 @@ type Completions interface { Query() string // Returns the current filter query KeyMap() KeyMap Position() (int, int) // Returns the X and Y position of the completions popup + Width() int + Height() int } type completionsCmp struct { @@ -54,6 +56,8 @@ type completionsCmp struct { query string // The current filter query } +const MaxCompletionsWidth = 80 // Maximum width for the completions popup + func New() Completions { completionsKeyMap := DefaultKeyMap() keyMap := list.DefaultKeyMap() @@ -92,7 +96,7 @@ func (c *completionsCmp) Init() tea.Cmd { func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: - c.width = min(msg.Width-c.x, 80) + c.width = min(msg.Width-c.x, MaxCompletionsWidth) c.height = min(msg.Height-c.y, 15) return c, nil case tea.KeyPressMsg: @@ -201,3 +205,11 @@ func (c *completionsCmp) KeyMap() KeyMap { func (c *completionsCmp) Position() (int, int) { return c.x, c.y - c.height } + +func (c *completionsCmp) Width() int { + return c.width +} + +func (c *completionsCmp) Height() int { + return c.height +} diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 0b10b74792c5cc6c91dc285d42a7d9a6736c2b90..811c18122687464d216e33f093aba60bbf5221c1 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -116,6 +116,16 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case completions.OpenCompletionsMsg, completions.FilterCompletionsMsg, completions.CloseCompletionsMsg: u, completionCmd := a.completions.Update(msg) a.completions = u.(completions.Completions) + switch msg := msg.(type) { + case completions.OpenCompletionsMsg: + x, _ := a.completions.Position() + if a.completions.Width()+x >= a.wWidth { + // Adjust X position to fit in the window. + msg.X = a.wWidth - a.completions.Width() - 1 + u, completionCmd = a.completions.Update(msg) + a.completions = u.(completions.Completions) + } + } return a, completionCmd // Dialog messages From 849572d4d0b50f8dee0d75ef5a3198d0b7119606 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 16 Jul 2025 09:40:37 -0400 Subject: [PATCH 2/2] fix(tui): completions: don't export variable --- internal/tui/components/completions/completions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index 1b3a09bc6b1a5d49fb8b10a9e19261da50742892..22e725596daace22153e9d26994b3218d2434959 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -56,7 +56,7 @@ type completionsCmp struct { query string // The current filter query } -const MaxCompletionsWidth = 80 // Maximum width for the completions popup +const maxCompletionsWidth = 80 // Maximum width for the completions popup func New() Completions { completionsKeyMap := DefaultKeyMap() @@ -96,7 +96,7 @@ func (c *completionsCmp) Init() tea.Cmd { func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: - c.width = min(msg.Width-c.x, MaxCompletionsWidth) + c.width = min(msg.Width-c.x, maxCompletionsWidth) c.height = min(msg.Height-c.y, 15) return c, nil case tea.KeyPressMsg: