@@ -127,6 +127,9 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127127 f.cursor = 0
128128 f.getCurrentFileBelowCursor()
129129 case tea.KeyMsg:
130+ if f.cwd.Focused() {
131+ f.cwd, cmd = f.cwd.Update(msg)
132+ }
130133 switch {
131134 case key.Matches(msg, filePickerKeyMap.InsertCWD):
132135 f.cwd.Focus()
@@ -165,7 +168,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
165168 isPathDir = f.dirs[f.cursor].IsDir()
166169 }
167170 if isPathDir {
168− path := filepath.Join(f.cwdDetails.directory, "/", f.dirs[f.cursor].Name())
169171 newWorkingDir := DirNode{parent: f.cwdDetails, directory: path}
170172 f.cwdDetails.child = &newWorkingDir
171173 f.cwdDetails = f.cwdDetails.child
@@ -216,9 +218,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
216218 f.getCurrentFileBelowCursor()
217219 }
218220 }
219− if f.cwd.Focused() {
220− f.cwd, cmd = f.cwd.Update(msg)
221− }
222221 return f, cmd
223222}
224223
@@ -228,37 +227,35 @@ func (f *filepickerCmp) addAttachmentToMessage() (tea.Model, tea.Cmd) {
228227 logging.ErrorPersist(fmt.Sprintf("Model %s doesn't support attachments", modeInfo.Name))
229228 return f, nil
230229 }
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)
235− if err != nil {
236− logging.ErrorPersist("unable to read the image")
237− return f, nil
238− }
239− if isFileLarge {
240− logging.ErrorPersist("file too large, max 5MB")
241− return f, nil
242− }
243230
244− content, err := os.ReadFile(selectedFilePath)
245− if err != nil {
246− logging.ErrorPersist("Unable read selected file")
247− return f, nil
248− }
231+ selectedFilePath := f.selectedFile
232+ if !isExtSupported(selectedFilePath) {
233+ logging.ErrorPersist("Unsupported file")
234+ return f, nil
235+ }
249236
250− mimeBufferSize := min(512, len(content))
251− mimeType := http.DetectContentType(content[:mimeBufferSize])
252− fileName := f.selectedFile
253− attachment := message.Attachment{FilePath: selectedFilePath, FileName: fileName, MimeType: mimeType, Content: content}
254− f.selectedFile = ""
255− return f, util.CmdHandler(AttachmentAddedMsg{attachment})
237+ isFileLarge, err := image.ValidateFileSize(selectedFilePath, maxAttachmentSize)
238+ if err != nil {
239+ logging.ErrorPersist("unable to read the image")
240+ return f, nil
256241 }
257− if !isExtSupported(f.selectedFile) {
258− logging.ErrorPersist("Unsupported file")
242+ if isFileLarge {
243+ logging.ErrorPersist("file too large, max 5MB")
259244 return f, nil
260245 }
261− return f, nil
246+
247+ content, err := os.ReadFile(selectedFilePath)
248+ if err != nil {
249+ logging.ErrorPersist("Unable read selected file")
250+ return f, nil
251+ }
252+
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}
257+ f.selectedFile = ""
258+ return f, util.CmdHandler(AttachmentAddedMsg{attachment})
262259}
263260
264261func (f *filepickerCmp) View() string {