@@ -7,7 +7,6 @@ import (
77 "runtime"
88 "slices"
99 "strings"
10− "time"
1110 "unicode"
1211
1312 "github.com/charmbracelet/bubbles/v2/key"
@@ -31,8 +30,6 @@ type FileCompletionItem struct {
3130 Path string // The file path
3231}
3332
34−type CompletionDebounceMsg struct{}
35−
3633type editorCmp struct {
3734 width int
3835 height int
@@ -49,9 +46,6 @@ type editorCmp struct {
4946 currentQuery string
5047 completionsStartIndex int
5148 isCompletionsOpen bool
52−
53− // Debouncing for completions
54− debounceTimer *time.Timer
5549}
5650
5751var DeleteKeyMaps = DeleteAttachmentKeyMaps{
@@ -147,22 +141,6 @@ func (m *editorCmp) send() tea.Cmd {
147141 )
148142}
149143
150−// debouncedCompletionFilter creates a debounced command for filtering completions
151−func (m *editorCmp) debouncedCompletionFilter() tea.Cmd {
152− // Cancel existing timer if any
153− if m.debounceTimer != nil {
154− m.debounceTimer.Stop()
155− }
156−
157− // Create new timer for debouncing
158− m.debounceTimer = time.NewTimer(150 * time.Millisecond)
159−
160− return func() tea.Msg {
161− <-m.debounceTimer.C
162− return CompletionDebounceMsg{}
163− }
164−}
165−
166144func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
167145 var cmd tea.Cmd
168146 var cmds []tea.Cmd
@@ -182,18 +160,6 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
182160 m.isCompletionsOpen = false
183161 m.currentQuery = ""
184162 m.completionsStartIndex = 0
185− // Cancel any pending debounce timer
186− if m.debounceTimer != nil {
187− m.debounceTimer.Stop()
188− m.debounceTimer = nil
189− }
190− case CompletionDebounceMsg:
191− // Handle debounced completion filtering
192− if m.isCompletionsOpen {
193− return m, util.CmdHandler(completions.FilterCompletionsMsg{
194− Query: m.currentQuery,
195− })
196− }
197163 case completions.SelectCompletionMsg:
198164 if !m.isCompletionsOpen {
199165 return m, nil
@@ -230,8 +196,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
230196 case msg.String() == "backspace" && m.isCompletionsOpen:
231197 if len(m.currentQuery) > 0 {
232198 m.currentQuery = m.currentQuery[:len(m.currentQuery)-1]
233− // Use debounced filtering instead of immediate filtering
234− cmds = append(cmds, m.debouncedCompletionFilter())
199+ cmds = append(cmds, util.CmdHandler(completions.FilterCompletionsMsg{
200+ Query: m.currentQuery,
201+ }))
235202 } else {
236203 m.isCompletionsOpen = false
237204 m.currentQuery = ""
@@ -241,8 +208,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
241208 default:
242209 if m.isCompletionsOpen {
243210 m.currentQuery += msg.String()
244− // Use debounced filtering instead of immediate filtering
245− cmds = append(cmds, m.debouncedCompletionFilter())
211+ cmds = append(cmds, util.CmdHandler(completions.FilterCompletionsMsg{
212+ Query: m.currentQuery,
213+ }))
246214 }
247215 }
248216 if key.Matches(msg, DeleteKeyMaps.AttachmentDeleteMode) {
@@ -388,11 +356,6 @@ func (m *editorCmp) startCompletions() tea.Msg {
388356// Blur implements Container.
389357func (c *editorCmp) Blur() tea.Cmd {
390358 c.textarea.Blur()
391− // Clean up debounce timer when losing focus
392− if c.debounceTimer != nil {
393− c.debounceTimer.Stop()
394− c.debounceTimer = nil
395− }
396359 return nil
397360}
398361