on main help sign in
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.

commit8e38daa0e45646bcd93be5404f58155c40293cc3 authorAyman Bagabas <ayman.bagabas@gmail.com> dateTue 8 Jul 2025, 17:04 (1 year ago) parentb0c9517
1 file changed+9−5
internal/tui/components/chat/editor/editor.go+9−5
internal/tui/components/chat/editor/editor.go+9−5
@@ -67,6 +67,10 @@ const (
6767 maxAttachments = 5
6868)
6969
70+type openEditorMsg struct {
71+ Text string
72+}
73+
7074func (m *editorCmp) openEditor(value string) tea.Cmd {
7175 editor := os.Getenv("EDITOR")
7276 if editor == "" {
@@ -102,11 +106,8 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
102106 return util.ReportWarn("Message is empty")
103107 }
104108 os.Remove(tmpfile.Name())
105− attachments := m.attachments
106− m.attachments = nil
107− return chat.SendMsg{
108− Text: string(content),
109− Attachments: attachments,
109+ return openEditorMsg{
110+ Text: strings.TrimSpace(string(content)),
110111 }
111112 })
112113}
@@ -184,6 +185,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
184185 m.completionsStartIndex = 0
185186 return m, nil
186187 }
188+ case openEditorMsg:
189+ m.textarea.SetValue(msg.Text)
190+ return m, nil
187191 case tea.KeyPressMsg:
188192 switch {
189193 // Completions