Browse Source

fix(tui): full paths for attachments

adamdottv 7 months ago
parent
commit
b8d276a049

+ 4 - 3
packages/tui/internal/components/chat/editor.go

@@ -109,7 +109,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				ID:        uuid.NewString(),
 				Display:   "@" + fileName,
 				URL:       fmt.Sprintf("file://./%s", filePath),
-				Filename:  fileName,
+				Filename:  filePath,
 				MediaType: mediaType,
 			}
 			m.textarea.InsertAttachment(attachment)
@@ -238,7 +238,8 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) {
 	}
 	if len(value) > 0 && value[len(value)-1] == '\\' {
 		// If the last character is a backslash, remove it and add a newline
-		m.textarea.SetValue(value[:len(value)-1] + "\n")
+		m.textarea.ReplaceRange(len(value)-1, len(value), "")
+		m.textarea.InsertString("\n")
 		return m, nil
 	}
 
@@ -284,7 +285,7 @@ func (m *editorComponent) Paste() (tea.Model, tea.Cmd) {
 	// 	}
 	// 	m.attachments = append(m.attachments, attachment)
 	// } else {
-	m.textarea.SetValue(m.textarea.Value() + text)
+	m.textarea.InsertString(text)
 	// }
 	return m, nil
 }

+ 3 - 3
packages/tui/internal/components/chat/messages.go

@@ -156,10 +156,11 @@ func (m *messagesComponent) renderView(width int) {
 								mediaType = "txt"
 							case "image/png", "image/jpeg", "image/gif", "image/webp":
 								mediaType = "img"
+								mediaTypeStyle = mediaTypeStyle.Background(t.Accent())
 							case "application/pdf":
 								mediaType = "pdf"
+								mediaTypeStyle = mediaTypeStyle.Background(t.Primary())
 							}
-
 							flexItems = append(flexItems, layout.FlexItem{
 								View: mediaTypeStyle.Render(mediaType) + fileStyle.Render(filePart.Filename),
 							})
@@ -170,8 +171,7 @@ func (m *messagesComponent) renderView(width int) {
 						layout.FlexOptions{
 							Background: &bgColor,
 							Width:      width - 6,
-							Direction:  layout.Row,
-							Gap:        3,
+							Direction:  layout.Column,
 						},
 						flexItems...,
 					)