From 4b2e52c834680301556ad103f7cd885071b8df6e Mon Sep 17 00:00:00 2001 From: plyght Date: Mon, 21 Jul 2025 17:31:29 +0200 Subject: feat(tui): paste minimizing (#784) Co-authored-by: adamdotdevin <2363879+adamdottv@users.noreply.github.com> --- packages/tui/internal/app/prompt.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'packages/tui/internal/app') diff --git a/packages/tui/internal/app/prompt.go b/packages/tui/internal/app/prompt.go index dcd0b97fa..158951d84 100644 --- a/packages/tui/internal/app/prompt.go +++ b/packages/tui/internal/app/prompt.go @@ -25,12 +25,32 @@ func (p Prompt) ToMessage( Created: float64(time.Now().UnixMilli()), }, } + + text := p.Text + textAttachments := []*attachment.Attachment{} + for _, attachment := range p.Attachments { + if attachment.Type == "text" { + textAttachments = append(textAttachments, attachment) + } + } + for i := 0; i < len(textAttachments)-1; i++ { + for j := i + 1; j < len(textAttachments); j++ { + if textAttachments[i].StartIndex < textAttachments[j].StartIndex { + textAttachments[i], textAttachments[j] = textAttachments[j], textAttachments[i] + } + } + } + for _, att := range textAttachments { + source, _ := att.GetTextSource() + text = text[:att.StartIndex] + source.Value + text[att.EndIndex:] + } + parts := []opencode.PartUnion{opencode.TextPart{ ID: id.Ascending(id.Part), MessageID: messageID, SessionID: sessionID, Type: opencode.TextPartTypeText, - Text: p.Text, + Text: text, }} for _, attachment := range p.Attachments { text := opencode.FilePartSourceText{ @@ -40,6 +60,8 @@ func (p Prompt) ToMessage( } var source *opencode.FilePartSource switch attachment.Type { + case "text": + continue case "file": fileSource, _ := attachment.GetFileSource() source = &opencode.FilePartSource{ -- cgit v1.2.3