diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 7c6d4a37767cfe8ea8f80fcc13a01ff504dfc580..8f79fc1c8d72708a489978b93c4447fa63b2cc82 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -174,42 +174,42 @@ func (m *editorCmp) repositionCompletions() tea.Msg { // 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 + 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 } - } - 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, - }) + 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, + }) */ } diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index 6796042c3674a41a4434bd05d8238d22b9715490..60d652d5e2afd4d30a5a0ee17946564fd44a29bb 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/internal/tui/components/chat/editor/editor_test.go @@ -5,8 +5,8 @@ import ( tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/crush/internal/app" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/zeebo/assert" ) func TestEditorTypingForwardSlashOpensCompletions(t *testing.T) {