on main help sign in
feat(tui): set the textarea value back after closing the editor
8e38daaAyman Bagabas
internal/tui/components/chat/editor/editor.go+9−5
@@ -67,6 +67,10 @@ const (
67 maxAttachments = 5
67 maxAttachments = 5
68)
68)
69
69
70+type openEditorMsg struct {
71+ Text string
72+}
73+
70func (m *editorCmp) openEditor(value string) tea.Cmd {
74func (m *editorCmp) openEditor(value string) tea.Cmd {
71 editor := os.Getenv("EDITOR")
75 editor := os.Getenv("EDITOR")
72 if editor == "" {
76 if editor == "" {
@@ -102,11 +106,8 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
102 return util.ReportWarn("Message is empty")
106 return util.ReportWarn("Message is empty")
103 }
107 }
104 os.Remove(tmpfile.Name())
108 os.Remove(tmpfile.Name())
105− attachments := m.attachments
109+ return openEditorMsg{
106− m.attachments = nil
107− return chat.SendMsg{
108− Text: string(content),
110+ Text: strings.TrimSpace(string(content)),
109− Attachments: attachments,
110 }
111 }
111 })
112 })
112}
113}
@@ -184,6 +185,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
184 m.completionsStartIndex = 0
185 m.completionsStartIndex = 0
185 return m, nil
186 return m, nil
186 }
187 }
188+ case openEditorMsg:
189+ m.textarea.SetValue(msg.Text)
190+ return m, nil
187 case tea.KeyPressMsg:
191 case tea.KeyPressMsg:
188 switch {
192 switch {
189 // Completions
193 // Completions