From 04cf7901beff4a76111af4c2edc3298b191bdb25 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Wed, 17 Sep 2025 10:33:54 +0100 Subject: [PATCH] refactor(editor): move message type inference to outside helper func --- internal/tui/components/chat/editor/editor.go | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index faef50e9a1484c8fe7aa7e02f85f843b80781111..6aae3b404196cceb40f074807d048fe25b3a2dd7 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -175,22 +175,20 @@ func (m *editorCmp) repositionCompletions() tea.Msg { return completions.RepositionCompletionsMsg{X: x, Y: y} } -func onCompletionItemSelect(msg completions.SelectCompletionMsg, m *editorCmp) { - if item, ok := msg.Value.(FileCompletionItem); ok { - word := m.textarea.Word() - // If the selected item is a file, insert its path into the textarea - value := m.textarea.Value() - value = value[:m.completionsStartIndex] + // Remove the current query - item.Path + // Insert the file path - value[m.completionsStartIndex+len(word):] // Append the rest of the value - // XXX: This will always move the cursor to the end of the textarea. - m.textarea.SetValue(value) - m.textarea.MoveToEnd() - if !msg.Insert { - m.isCompletionsOpen = false - m.currentQuery = "" - m.completionsStartIndex = 0 - } +func onCompletionItemSelect(item FileCompletionItem, insert bool, m *editorCmp) { + word := m.textarea.Word() + // If the selected item is a file, insert its path into the textarea + value := m.textarea.Value() + value = value[:m.completionsStartIndex] + // Remove the current query + item.Path + // Insert the file path + value[m.completionsStartIndex+len(word):] // Append the rest of the value + // XXX: This will always move the cursor to the end of the textarea. + m.textarea.SetValue(value) + m.textarea.MoveToEnd() + if !insert { + m.isCompletionsOpen = false + m.currentQuery = "" + m.completionsStartIndex = 0 } } @@ -261,7 +259,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if !m.isCompletionsOpen { return m, nil } - onCompletionItemSelect(msg, m) + if item, ok := msg.Value.(FileCompletionItem); ok { + onCompletionItemSelect(item, msg.Insert, m) + } case commands.OpenExternalEditorMsg: if m.app.CoderAgent.IsSessionBusy(m.session.ID) { return m, util.ReportWarn("Agent is working, please wait...")