Skip to content

Commit 8690e3f

Browse files
feat(tui): collapse large pasted file contents
1 parent 4824614 commit 8690e3f

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

pkg/tui/components/editor/editor.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,21 +567,27 @@ func (e *editor) resetAndSend(content string) tea.Cmd {
567567
e.pendingFileRef = ""
568568
attachments := e.collectAttachments(content)
569569

570-
// Sort attachments by name length descending to avoid partial matches
571-
// e.g., replacing @paste-1 before @paste-10 would corrupt @paste-10.
572-
slices.SortFunc(attachments, func(a, b messages.Attachment) int {
573-
return len(b.Name) - len(a.Name)
574-
})
575-
576570
var finalAttachments []messages.Attachment
571+
var pastes []messages.Attachment
572+
577573
for _, att := range attachments {
578574
if att.Content != "" && strings.HasPrefix(att.Name, "paste-") {
579-
content = strings.ReplaceAll(content, "@"+att.Name, att.Content)
575+
pastes = append(pastes, att)
580576
} else {
581577
finalAttachments = append(finalAttachments, att)
582578
}
583579
}
584580

581+
// Sort pastes by name length descending to avoid partial matches
582+
// e.g., replacing @paste-1 before @paste-10 would corrupt @paste-10.
583+
slices.SortFunc(pastes, func(a, b messages.Attachment) int {
584+
return len(b.Name) - len(a.Name)
585+
})
586+
587+
for _, att := range pastes {
588+
content = strings.ReplaceAll(content, "@"+att.Name, att.Content)
589+
}
590+
585591
e.textarea.Reset()
586592
e.userTyped = false
587593
e.clearSuggestion()

0 commit comments

Comments
 (0)