From 91b05f57f57e0bc63c7401dc930b1f083c61b1c8 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 8 Jul 2025 17:03:01 -0400 Subject: [PATCH 1/2] fix(tui): copy textarea value to editor on open --- internal/tui/components/chat/editor/editor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 30d3aeef80c57487e665952f699cd7b4522db214..4b94900903cce6dc5105d384e78e200301c3fc2d 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -67,7 +67,7 @@ const ( maxAttachments = 5 ) -func (m *editorCmp) openEditor() tea.Cmd { +func (m *editorCmp) openEditor(value string) tea.Cmd { editor := os.Getenv("EDITOR") if editor == "" { // Use platform-appropriate default editor @@ -82,6 +82,7 @@ func (m *editorCmp) openEditor() tea.Cmd { if err != nil { return util.ReportError(err) } + _, _ = tmpfile.WriteString(value) tmpfile.Close() c := exec.Command(editor, tmpfile.Name()) c.Stdin = os.Stdin @@ -239,7 +240,7 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.app.CoderAgent.IsSessionBusy(m.session.ID) { return m, util.ReportWarn("Agent is working, please wait...") } - return m, m.openEditor() + return m, m.openEditor(m.textarea.Value()) } if key.Matches(msg, DeleteKeyMaps.Escape) { m.deleteMode = false From 0016e441ebc803cac346e11312470cb642be3eb4 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 10 Jul 2025 10:31:09 -0400 Subject: [PATCH 2/2] chore(tui): editor: return error on write failure --- internal/tui/components/chat/editor/editor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 4b94900903cce6dc5105d384e78e200301c3fc2d..5f8a3548aa47810c3583f6d2b6a6c184809ba178 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -82,8 +82,10 @@ func (m *editorCmp) openEditor(value string) tea.Cmd { if err != nil { return util.ReportError(err) } - _, _ = tmpfile.WriteString(value) - tmpfile.Close() + defer tmpfile.Close() //nolint:errcheck + if _, err := tmpfile.WriteString(value); err != nil { + return util.ReportError(err) + } c := exec.Command(editor, tmpfile.Name()) c.Stdin = os.Stdin c.Stdout = os.Stdout