on main help sign in
fix: remove debouncer
ff4ca8eRaphael Amorim
internal/tui/components/chat/editor/editor.go+6−43
@@ -7,7 +7,6 @@ import (
7 "runtime"
7 "runtime"
8 "slices"
8 "slices"
9 "strings"
9 "strings"
10− "time"
11 "unicode"
10 "unicode"
12
11
13 "github.com/charmbracelet/bubbles/v2/key"
12 "github.com/charmbracelet/bubbles/v2/key"
@@ -31,8 +30,6 @@ type FileCompletionItem struct {
31 Path string // The file path
30 Path string // The file path
32}
31}
33
32
34−type CompletionDebounceMsg struct{}
35−
36type editorCmp struct {
33type editorCmp struct {
37 width int
34 width int
38 height int
35 height int
@@ -49,9 +46,6 @@ type editorCmp struct {
49 currentQuery string
46 currentQuery string
50 completionsStartIndex int
47 completionsStartIndex int
51 isCompletionsOpen bool
48 isCompletionsOpen bool
52−
53− // Debouncing for completions
54− debounceTimer *time.Timer
55}
49}
56
50
57var DeleteKeyMaps = DeleteAttachmentKeyMaps{
51var DeleteKeyMaps = DeleteAttachmentKeyMaps{
@@ -147,22 +141,6 @@ func (m *editorCmp) send() tea.Cmd {
147 )
141 )
148}
142}
149
143
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−
166func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
144func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
167 var cmd tea.Cmd
145 var cmd tea.Cmd
168 var cmds []tea.Cmd
146 var cmds []tea.Cmd
@@ -182,18 +160,6 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
182 m.isCompletionsOpen = false
160 m.isCompletionsOpen = false
183 m.currentQuery = ""
161 m.currentQuery = ""
184 m.completionsStartIndex = 0
162 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− }
197 case completions.SelectCompletionMsg:
163 case completions.SelectCompletionMsg:
198 if !m.isCompletionsOpen {
164 if !m.isCompletionsOpen {
199 return m, nil
165 return m, nil
@@ -230,8 +196,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
230 case msg.String() == "backspace" && m.isCompletionsOpen:
196 case msg.String() == "backspace" && m.isCompletionsOpen:
231 if len(m.currentQuery) > 0 {
197 if len(m.currentQuery) > 0 {
232 m.currentQuery = m.currentQuery[:len(m.currentQuery)-1]
198 m.currentQuery = m.currentQuery[:len(m.currentQuery)-1]
233− // Use debounced filtering instead of immediate filtering
199+ cmds = append(cmds, util.CmdHandler(completions.FilterCompletionsMsg{
234− cmds = append(cmds, m.debouncedCompletionFilter())
200+ Query: m.currentQuery,
201+ }))
235 } else {
202 } else {
236 m.isCompletionsOpen = false
203 m.isCompletionsOpen = false
237 m.currentQuery = ""
204 m.currentQuery = ""
@@ -241,8 +208,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
241 default:
208 default:
242 if m.isCompletionsOpen {
209 if m.isCompletionsOpen {
243 m.currentQuery += msg.String()
210 m.currentQuery += msg.String()
244− // Use debounced filtering instead of immediate filtering
211+ cmds = append(cmds, util.CmdHandler(completions.FilterCompletionsMsg{
245− cmds = append(cmds, m.debouncedCompletionFilter())
212+ Query: m.currentQuery,
213+ }))
246 }
214 }
247 }
215 }
248 if key.Matches(msg, DeleteKeyMaps.AttachmentDeleteMode) {
216 if key.Matches(msg, DeleteKeyMaps.AttachmentDeleteMode) {
@@ -388,11 +356,6 @@ func (m *editorCmp) startCompletions() tea.Msg {
388// Blur implements Container.
356// Blur implements Container.
389func (c *editorCmp) Blur() tea.Cmd {
357func (c *editorCmp) Blur() tea.Cmd {
390 c.textarea.Blur()
358 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− }
396 return nil
359 return nil
397}
360}
398
361