@@ -127,6 +127,9 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127 f.cursor = 0
127 f.cursor = 0
128 f.getCurrentFileBelowCursor()
128 f.getCurrentFileBelowCursor()
129 case tea.KeyMsg:
129 case tea.KeyMsg:
130+ if f.cwd.Focused() {
131+ f.cwd, cmd = f.cwd.Update(msg)
131 case key.Matches(msg, filePickerKeyMap.InsertCWD):
134 case key.Matches(msg, filePickerKeyMap.InsertCWD):
132 f.cwd.Focus()
135 f.cwd.Focus()
@@ -165,7 +168,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
165 isPathDir = f.dirs[f.cursor].IsDir()
168 isPathDir = f.dirs[f.cursor].IsDir()
167 if isPathDir {
170 if isPathDir {
168− path := filepath.Join(f.cwdDetails.directory, "/", f.dirs[f.cursor].Name())
169 newWorkingDir := DirNode{parent: f.cwdDetails, directory: path}
171 newWorkingDir := DirNode{parent: f.cwdDetails, directory: path}
170 f.cwdDetails.child = &newWorkingDir
172 f.cwdDetails.child = &newWorkingDir
171 f.cwdDetails = f.cwdDetails.child
173 f.cwdDetails = f.cwdDetails.child
@@ -216,9 +218,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
216 f.getCurrentFileBelowCursor()
218 f.getCurrentFileBelowCursor()
219− if f.cwd.Focused() {
220− f.cwd, cmd = f.cwd.Update(msg)
222 return f, cmd
221 return f, cmd
@@ -228,37 +227,35 @@ func (f *filepickerCmp) addAttachmentToMessage() (tea.Model, tea.Cmd) {
228 logging.ErrorPersist(fmt.Sprintf("Model %s doesn't support attachments", modeInfo.Name))
227 logging.ErrorPersist(fmt.Sprintf("Model %s doesn't support attachments", modeInfo.Name))
229 return f, nil
228 return f, nil
231− if isExtSupported(f.dirs[f.cursor].Name()) {
232− f.selectedFile = f.dirs[f.cursor].Name()
233− selectedFilePath := filepath.Join(f.cwdDetails.directory, "/", f.selectedFile)
234− isFileLarge, err := image.ValidateFileSize(selectedFilePath, maxAttachmentSize)
236− logging.ErrorPersist("unable to read the image")
240− logging.ErrorPersist("file too large, max 5MB")
244− content, err := os.ReadFile(selectedFilePath)
231+ selectedFilePath := f.selectedFile
245− if err != nil {
232+ if !isExtSupported(selectedFilePath) {
246− logging.ErrorPersist("Unable read selected file")
233+ logging.ErrorPersist("Unsupported file")
247− return f, nil
234+ return f, nil
250− mimeBufferSize := min(512, len(content))
237+ isFileLarge, err := image.ValidateFileSize(selectedFilePath, maxAttachmentSize)
251− mimeType := http.DetectContentType(content[:mimeBufferSize])
238+ if err != nil {
252− fileName := f.selectedFile
239+ logging.ErrorPersist("unable to read the image")
253− attachment := message.Attachment{FilePath: selectedFilePath, FileName: fileName, MimeType: mimeType, Content: content}
240+ return f, nil
255− return f, util.CmdHandler(AttachmentAddedMsg{attachment})
257− if !isExtSupported(f.selectedFile) {
242+ if isFileLarge {
258− logging.ErrorPersist("Unsupported file")
243+ logging.ErrorPersist("file too large, max 5MB")
259 return f, nil
244 return f, nil
247+ content, err := os.ReadFile(selectedFilePath)
249+ logging.ErrorPersist("Unable read selected file")
261− return f, nil
250+ return f, nil
253+ mimeBufferSize := min(512, len(content))
254+ mimeType := http.DetectContentType(content[:mimeBufferSize])
255+ fileName := filepath.Base(selectedFilePath)
256+ attachment := message.Attachment{FilePath: selectedFilePath, FileName: fileName, MimeType: mimeType, Content: content}
258+ return f, util.CmdHandler(AttachmentAddedMsg{attachment})
264func (f *filepickerCmp) View() string {
261func (f *filepickerCmp) View() string {