mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
fix(tui): handle pdf and image @ files
This commit is contained in:
parent
94ef341c9d
commit
f6108b7be8
1 changed files with 13 additions and 1 deletions
|
@ -93,12 +93,24 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
// The cursor is now at `atIndex` after the replacement.
|
// The cursor is now at `atIndex` after the replacement.
|
||||||
filePath := msg.CompletionValue
|
filePath := msg.CompletionValue
|
||||||
fileName := filepath.Base(filePath)
|
fileName := filepath.Base(filePath)
|
||||||
|
extension := filepath.Ext(filePath)
|
||||||
|
mediaType := ""
|
||||||
|
switch extension {
|
||||||
|
case ".jpg":
|
||||||
|
mediaType = "image/jpeg"
|
||||||
|
case ".png", ".jpeg", ".gif", ".webp":
|
||||||
|
mediaType = "image/" + extension[1:]
|
||||||
|
case ".pdf":
|
||||||
|
mediaType = "application/pdf"
|
||||||
|
default:
|
||||||
|
mediaType = "text/plain"
|
||||||
|
}
|
||||||
attachment := &textarea.Attachment{
|
attachment := &textarea.Attachment{
|
||||||
ID: uuid.NewString(),
|
ID: uuid.NewString(),
|
||||||
Display: "@" + fileName,
|
Display: "@" + fileName,
|
||||||
URL: fmt.Sprintf("file://%s", filePath),
|
URL: fmt.Sprintf("file://%s", filePath),
|
||||||
Filename: fileName,
|
Filename: fileName,
|
||||||
MediaType: "text/plain",
|
MediaType: mediaType,
|
||||||
}
|
}
|
||||||
m.textarea.InsertAttachment(attachment)
|
m.textarea.InsertAttachment(attachment)
|
||||||
m.textarea.InsertString(" ")
|
m.textarea.InsertString(" ")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue