From 7216a8c86d964207083784f2d3d595a5affb9518 Mon Sep 17 00:00:00 2001 From: kcrommett <523952+kcrommett@users.noreply.github.com> Date: Mon, 27 Oct 2025 15:51:33 -0700 Subject: [PATCH] fix: editor paste functionality for text attachments (#3489) --- packages/tui/internal/components/chat/editor.go | 7 +++++-- packages/tui/internal/tui/tui.go | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 2841e2cc..d3c81384 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -48,6 +48,7 @@ type EditorComponent interface { SetInterruptKeyInDebounce(inDebounce bool) SetExitKeyInDebounce(inDebounce bool) RestoreFromHistory(index int) + GetAttachments() []*attachment.Attachment } type editorComponent struct { @@ -471,6 +472,10 @@ func (m *editorComponent) Length() int { return m.textarea.Length() } +func (m *editorComponent) GetAttachments() []*attachment.Attachment { + return m.textarea.GetAttachments() +} + func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { value := strings.TrimSpace(m.Value()) if value == "" { @@ -628,9 +633,7 @@ func (m *editorComponent) SetValueWithAttachments(value string) { } if end > start { filePath := value[start:end] - slog.Debug("test", "filePath", filePath) if _, err := os.Stat(filepath.Join(util.CwdPath, filePath)); err == nil { - slog.Debug("test", "found", true) attachment := m.createAttachmentFromFile(filePath) if attachment != nil { m.textarea.InsertAttachment(attachment) diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go index 69fa7bdb..27944367 100644 --- a/packages/tui/internal/tui/tui.go +++ b/packages/tui/internal/tui/tui.go @@ -1164,6 +1164,14 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) { } value := a.editor.Value() + + // Expand text attachments before opening editor + for _, att := range a.editor.GetAttachments() { + if textSource, ok := att.GetTextSource(); ok { + value = strings.Replace(value, att.Display, textSource.Value, 1) + } + } + updated, cmd := a.editor.Clear() a.editor = updated.(chat.EditorComponent) cmds = append(cmds, cmd)