diff --git a/internal/ui/completions/completions.go b/internal/ui/completions/completions.go index 496cd5a56be71fcc7d713be7f9c384fd8c58a307..4a4f9d8133491b8a7b80df6066b9e86c7e852a85 100644 --- a/internal/ui/completions/completions.go +++ b/internal/ui/completions/completions.go @@ -29,6 +29,11 @@ type SelectionMsg struct { // ClosedMsg is sent when the completions are closed. type ClosedMsg struct{} +// FilesLoadedMsg is sent when files have been loaded for completions. +type FilesLoadedMsg struct { + Files []string +} + // Completions represents the completions popup component. type Completions struct { // Popup dimensions @@ -88,10 +93,12 @@ func (c *Completions) KeyMap() KeyMap { } // OpenWithFiles opens the completions with file items from the filesystem. -func (c *Completions) OpenWithFiles(depth, limit int) { - files, _, _ := fsext.ListDirectory(".", nil, depth, limit) - slices.Sort(files) - c.SetFiles(files) +func (c *Completions) OpenWithFiles(depth, limit int) tea.Cmd { + return func() tea.Msg { + files, _, _ := fsext.ListDirectory(".", nil, depth, limit) + slices.Sort(files) + return FilesLoadedMsg{Files: files} + } } // SetFiles sets the file items on the completions popup. diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index f7010369b3592cf3f731c30a8eaf2a5ffed4adf7..c06ea6f7ada0180c3a8ffbbeff92430a9c0ff641 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -371,6 +371,11 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, clearInfoMsgCmd(ttl)) case uiutil.ClearStatusMsg: m.status.ClearInfoMsg() + case completions.FilesLoadedMsg: + // Handle async file loading for completions. + if m.completionsOpen { + m.completions.SetFiles(msg.Files) + } } // This logic gets triggered on any message type, but should it? @@ -878,7 +883,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd { m.completionsStartIndex = curIdx m.completionsPositionStart = m.completionsPosition() depth, limit := m.com.Config().Options.TUI.Completions.Limits() - m.completions.OpenWithFiles(depth, limit) + cmds = append(cmds, m.completions.OpenWithFiles(depth, limit)) } }