Просмотр исходного кода

tweak: handle pasted attachment references (#1257)

Aiden Cline 7 месяцев назад
Родитель
Сommit
289a4d9b18
1 измененных файлов с 16 добавлено и 0 удалено
  1. 16 0
      packages/tui/internal/components/chat/editor.go

+ 16 - 0
packages/tui/internal/components/chat/editor.go

@@ -128,6 +128,22 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		}
 	case tea.PasteMsg:
 		text := string(msg)
+
+		if filePath := strings.TrimSpace(strings.TrimPrefix(text, "@")); strings.HasPrefix(text, "@") && filePath != "" {
+			statPath := filePath
+			if !filepath.IsAbs(filePath) {
+				statPath = filepath.Join(m.app.Info.Path.Cwd, filePath)
+			}
+			if _, err := os.Stat(statPath); err == nil {
+				attachment := m.createAttachmentFromPath(filePath)
+				if attachment != nil {
+					m.textarea.InsertAttachment(attachment)
+					m.textarea.InsertString(" ")
+					return m, nil
+				}
+			}
+		}
+
 		text = strings.ReplaceAll(text, "\\", "")
 		text, err := strconv.Unquote(`"` + text + `"`)
 		if err != nil {