chore(editor): move intended shared logic for emitting an attachment message

tauraamui created

Change summary

internal/tui/components/chat/editor/editor.go | 44 ++++++++++++++++++++
1 file changed, 43 insertions(+), 1 deletion(-)

Detailed changes

internal/tui/components/chat/editor/editor.go 🔗

@@ -171,6 +171,48 @@ func (m *editorCmp) repositionCompletions() tea.Msg {
 	return completions.RepositionCompletionsMsg{X: x, Y: y}
 }
 
+// NOTE(tauraamui) [12/09/2025]: I want to use this shared logic to denote an attachment event
+func handleSelectedPath(path string) {
+	/*
+	path = strings.ReplaceAll(string(path), "\\ ", " ")
+	// try to get an image
+	path, err := filepath.Abs(strings.TrimSpace(path))
+	if err != nil {
+		m.textarea, cmd = m.textarea.Update(msg)
+		return m, cmd
+	}
+	isAllowedType := false
+	for _, ext := range filepicker.AllowedTypes {
+		if strings.HasSuffix(path, ext) {
+			isAllowedType = true
+			break
+		}
+	}
+	if !isAllowedType {
+		m.textarea, cmd = m.textarea.Update(msg)
+		return m, cmd
+	}
+	tooBig, _ := filepicker.IsFileTooBig(path, filepicker.MaxAttachmentSize)
+	if tooBig {
+		m.textarea, cmd = m.textarea.Update(msg)
+		return m, cmd
+	}
+
+	content, err := os.ReadFile(path)
+	if err != nil {
+		m.textarea, cmd = m.textarea.Update(msg)
+		return m, cmd
+	}
+	mimeBufferSize := min(512, len(content))
+	mimeType := http.DetectContentType(content[:mimeBufferSize])
+	fileName := filepath.Base(path)
+	attachment := message.Attachment{FilePath: path, FileName: fileName, MimeType: mimeType, Content: content}
+	return m, util.CmdHandler(filepicker.FilePickedMsg{
+		Attachment: attachment,
+	})
+	*/
+}
+
 func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	var cmd tea.Cmd
 	var cmds []tea.Cmd
@@ -576,7 +618,7 @@ func newTextArea() *textarea.Model {
 	return ta
 }
 
-func newEditor(app *app.App) Editor {
+func newEditor(app *app.App) *editorCmp {
 	e := editorCmp{
 		// TODO: remove the app instance from here
 		app:      app,