@@ -127,6 +127,9 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127
127
f .cursor = 0
128
128
f .getCurrentFileBelowCursor ()
129
129
case tea.KeyMsg :
130
+ if f .cwd .Focused () {
131
+ f .cwd , cmd = f .cwd .Update (msg )
132
+ }
130
133
switch {
131
134
case key .Matches (msg , filePickerKeyMap .InsertCWD ):
132
135
f .cwd .Focus ()
@@ -165,7 +168,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
165
168
isPathDir = f .dirs [f .cursor ].IsDir ()
166
169
}
167
170
if isPathDir {
168
- path := filepath .Join (f .cwdDetails .directory , "/" , f .dirs [f .cursor ].Name ())
169
171
newWorkingDir := DirNode {parent : f .cwdDetails , directory : path }
170
172
f .cwdDetails .child = & newWorkingDir
171
173
f .cwdDetails = f .cwdDetails .child
@@ -216,9 +218,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
216
218
f .getCurrentFileBelowCursor ()
217
219
}
218
220
}
219
- if f .cwd .Focused () {
220
- f .cwd , cmd = f .cwd .Update (msg )
221
- }
222
221
return f , cmd
223
222
}
224
223
@@ -228,37 +227,35 @@ func (f *filepickerCmp) addAttachmentToMessage() (tea.Model, tea.Cmd) {
228
227
logging .ErrorPersist (fmt .Sprintf ("Model %s doesn't support attachments" , modeInfo .Name ))
229
228
return f , nil
230
229
}
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
- }
243
230
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
+ }
249
236
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
256
241
}
257
- if ! isExtSupported ( f . selectedFile ) {
258
- logging .ErrorPersist ("Unsupported file" )
242
+ if isFileLarge {
243
+ logging .ErrorPersist ("file too large, max 5MB " )
259
244
return f , nil
260
245
}
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 })
262
259
}
263
260
264
261
func (f * filepickerCmp ) View () string {
0 commit comments