From 8e38daa0e45646bcd93be5404f58155c40293cc3 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 8 Jul 2025 17:04:26 -0400 Subject: [PATCH] feat(tui): set the textarea value back after closing the editor After closing the editor, the textarea value becomes the text that was written in the editor. This allows users to edit the text they wrote in the editor before sending it. --- internal/tui/components/chat/editor/editor.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index ee374a6c1e0e68aaebef74fee07edb62292d68fe..272ef2f8f78020a16e88e5eac73756ea8473fe4b 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -67,6 +67,10 @@ const ( maxAttachments = 5 ) +type openEditorMsg struct { + Text string +} + func (m *editorCmp) openEditor(value string) tea.Cmd { editor := os.Getenv("EDITOR") if editor == "" { @@ -102,11 +106,8 @@ func (m *editorCmp) openEditor(value string) tea.Cmd { return util.ReportWarn("Message is empty") } os.Remove(tmpfile.Name()) - attachments := m.attachments - m.attachments = nil - return chat.SendMsg{ - Text: string(content), - Attachments: attachments, + return openEditorMsg{ + Text: strings.TrimSpace(string(content)), } }) } @@ -184,6 +185,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.completionsStartIndex = 0 return m, nil } + case openEditorMsg: + m.textarea.SetValue(msg.Text) + return m, nil case tea.KeyPressMsg: switch { // Completions