mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-08 18:34:59 +01:00
Fix filepicker manual input (#146)
* fix: allows to type i while manual inputting filepath * fix: file selection in filepicker focus mode * remove duplicate code
This commit is contained in:
committed by
adamdottv
parent
17c5b9c12c
commit
4bb350a09b
@@ -128,6 +128,9 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
f.cursor = 0
|
f.cursor = 0
|
||||||
f.getCurrentFileBelowCursor()
|
f.getCurrentFileBelowCursor()
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
if f.cwd.Focused() {
|
||||||
|
f.cwd, cmd = f.cwd.Update(msg)
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, filePickerKeyMap.InsertCWD):
|
case key.Matches(msg, filePickerKeyMap.InsertCWD):
|
||||||
f.cwd.Focus()
|
f.cwd.Focus()
|
||||||
@@ -166,7 +169,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
isPathDir = f.dirs[f.cursor].IsDir()
|
isPathDir = f.dirs[f.cursor].IsDir()
|
||||||
}
|
}
|
||||||
if isPathDir {
|
if isPathDir {
|
||||||
path := filepath.Join(f.cwdDetails.directory, "/", f.dirs[f.cursor].Name())
|
|
||||||
newWorkingDir := DirNode{parent: f.cwdDetails, directory: path}
|
newWorkingDir := DirNode{parent: f.cwdDetails, directory: path}
|
||||||
f.cwdDetails.child = &newWorkingDir
|
f.cwdDetails.child = &newWorkingDir
|
||||||
f.cwdDetails = f.cwdDetails.child
|
f.cwdDetails = f.cwdDetails.child
|
||||||
@@ -217,9 +219,6 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
f.getCurrentFileBelowCursor()
|
f.getCurrentFileBelowCursor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if f.cwd.Focused() {
|
|
||||||
f.cwd, cmd = f.cwd.Update(msg)
|
|
||||||
}
|
|
||||||
return f, cmd
|
return f, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,37 +228,35 @@ func (f *filepickerCmp) addAttachmentToMessage() (tea.Model, tea.Cmd) {
|
|||||||
status.Error(fmt.Sprintf("Model %s doesn't support attachments", modeInfo.Name))
|
status.Error(fmt.Sprintf("Model %s doesn't support attachments", modeInfo.Name))
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
if isExtSupported(f.dirs[f.cursor].Name()) {
|
|
||||||
f.selectedFile = f.dirs[f.cursor].Name()
|
|
||||||
selectedFilePath := filepath.Join(f.cwdDetails.directory, "/", f.selectedFile)
|
|
||||||
isFileLarge, err := image.ValidateFileSize(selectedFilePath, maxAttachmentSize)
|
|
||||||
if err != nil {
|
|
||||||
status.Error("unable to read the image")
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
if isFileLarge {
|
|
||||||
status.Error("file too large, max 5MB")
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := os.ReadFile(selectedFilePath)
|
selectedFilePath := f.selectedFile
|
||||||
if err != nil {
|
if !isExtSupported(selectedFilePath) {
|
||||||
status.Error("Unable read selected file")
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
mimeBufferSize := min(512, len(content))
|
|
||||||
mimeType := http.DetectContentType(content[:mimeBufferSize])
|
|
||||||
fileName := f.selectedFile
|
|
||||||
attachment := message.Attachment{FilePath: selectedFilePath, FileName: fileName, MimeType: mimeType, Content: content}
|
|
||||||
f.selectedFile = ""
|
|
||||||
return f, util.CmdHandler(AttachmentAddedMsg{attachment})
|
|
||||||
}
|
|
||||||
if !isExtSupported(f.selectedFile) {
|
|
||||||
status.Error("Unsupported file")
|
status.Error("Unsupported file")
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
return f, nil
|
|
||||||
|
isFileLarge, err := image.ValidateFileSize(selectedFilePath, maxAttachmentSize)
|
||||||
|
if err != nil {
|
||||||
|
status.Error("unable to read the image")
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
if isFileLarge {
|
||||||
|
status.Error("file too large, max 5MB")
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := os.ReadFile(selectedFilePath)
|
||||||
|
if err != nil {
|
||||||
|
status.Error("Unable read selected file")
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mimeBufferSize := min(512, len(content))
|
||||||
|
mimeType := http.DetectContentType(content[:mimeBufferSize])
|
||||||
|
fileName := filepath.Base(selectedFilePath)
|
||||||
|
attachment := message.Attachment{FilePath: selectedFilePath, FileName: fileName, MimeType: mimeType, Content: content}
|
||||||
|
f.selectedFile = ""
|
||||||
|
return f, util.CmdHandler(AttachmentAddedMsg{attachment})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *filepickerCmp) View() string {
|
func (f *filepickerCmp) View() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user