Skip to content

Commit 09074dc

Browse files
authored
fix: attachment highlighting (anomalyco#1427)
1 parent 1b3d58e commit 09074dc

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

packages/tui/internal/components/chat/message.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func renderText(
182182
showToolDetails bool,
183183
width int,
184184
extra string,
185+
fileParts []opencode.FilePart,
185186
toolCalls ...opencode.ToolPart,
186187
) string {
187188
t := theme.CurrentTheme()
@@ -197,19 +198,15 @@ func renderText(
197198
ts = time.UnixMilli(int64(casted.Time.Created))
198199
base := styles.NewStyle().Foreground(t.Text()).Background(backgroundColor)
199200
text = ansi.WordwrapWc(text, width-6, " -")
200-
lines := strings.Split(text, "\n")
201-
for i, line := range lines {
202-
words := strings.Fields(line)
203-
for i, word := range words {
204-
if strings.HasPrefix(word, "@") {
205-
words[i] = base.Foreground(t.Secondary()).Render(word + " ")
206-
} else {
207-
words[i] = base.Render(word + " ")
208-
}
209-
}
210-
lines[i] = strings.Join(words, "")
201+
202+
// Build list of attachment filenames for highlighting
203+
for _, filePart := range fileParts {
204+
atFilename := "@" + filePart.Filename
205+
// Find and highlight complete @filename references
206+
highlightStyle := base.Foreground(t.Secondary())
207+
text = strings.ReplaceAll(text, atFilename, highlightStyle.Render(atFilename))
211208
}
212-
text = strings.Join(lines, "\n")
209+
213210
content = base.Width(width - 6).Render(text)
214211
}
215212

packages/tui/internal/components/chat/messages.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
347347
m.showToolDetails,
348348
width,
349349
files,
350+
fileParts,
350351
)
351352
content = lipgloss.PlaceHorizontal(
352353
m.width,
@@ -424,6 +425,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
424425
m.showToolDetails,
425426
width,
426427
"",
428+
[]opencode.FilePart{},
427429
toolCallParts...,
428430
)
429431
content = lipgloss.PlaceHorizontal(
@@ -443,6 +445,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
443445
m.showToolDetails,
444446
width,
445447
"",
448+
[]opencode.FilePart{},
446449
toolCallParts...,
447450
)
448451
content = lipgloss.PlaceHorizontal(

0 commit comments

Comments
 (0)