diff options
| author | Yihui Khuu <[email protected]> | 2025-08-03 00:26:44 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-02 09:26:44 -0500 |
| commit | 8ad83f71a9f2e02e705301a72c3d0c39c3d9055d (patch) | |
| tree | c1b198ebe3705b21387fe6398c5e6dba3e70c82f | |
| parent | fa95c09cdce6e212be1b2c8d6b2a07f701821770 (diff) | |
| download | opencode-8ad83f71a9f2e02e705301a72c3d0c39c3d9055d.tar.gz opencode-8ad83f71a9f2e02e705301a72c3d0c39c3d9055d.zip | |
fix(tui): attachment highlighting issues in messages (#1534)
| -rw-r--r-- | packages/tui/internal/components/chat/message.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/packages/tui/internal/components/chat/message.go b/packages/tui/internal/components/chat/message.go index 35580386e..29920efdd 100644 --- a/packages/tui/internal/components/chat/message.go +++ b/packages/tui/internal/components/chat/message.go @@ -217,15 +217,27 @@ func renderText( base := styles.NewStyle().Foreground(t.Text()).Background(backgroundColor) text = ansi.WordwrapWc(text, width-6, " -") - // Build list of attachment filenames for highlighting + var result strings.Builder + lastEnd := int64(0) + + // Apply highlighting to filenames and base style to rest of text for _, filePart := range fileParts { - atFilename := "@" + filePart.Filename - // Find and highlight complete @filename references - highlightStyle := base.Foreground(t.Secondary()) - text = strings.ReplaceAll(text, atFilename, highlightStyle.Render(atFilename)) + highlight := base.Foreground(t.Secondary()) + start, end := filePart.Source.Text.Start, filePart.Source.Text.End + + if start > lastEnd { + result.WriteString(base.Render(text[lastEnd:start])) + } + result.WriteString(highlight.Render(text[start:end])) + + lastEnd = end + } + + if lastEnd < int64(len(text)) { + result.WriteString(base.Render(text[lastEnd:])) } - content = base.Width(width - 6).Render(text) + content = base.Width(width - 6).Render(result.String()) } timestamp := ts. |
