Skip to content

Commit 8ad83f7

Browse files
authored
fix(tui): attachment highlighting issues in messages (anomalyco#1534)
1 parent fa95c09 commit 8ad83f7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,27 @@ func renderText(
217217
base := styles.NewStyle().Foreground(t.Text()).Background(backgroundColor)
218218
text = ansi.WordwrapWc(text, width-6, " -")
219219

220-
// Build list of attachment filenames for highlighting
220+
var result strings.Builder
221+
lastEnd := int64(0)
222+
223+
// Apply highlighting to filenames and base style to rest of text
221224
for _, filePart := range fileParts {
222-
atFilename := "@" + filePart.Filename
223-
// Find and highlight complete @filename references
224-
highlightStyle := base.Foreground(t.Secondary())
225-
text = strings.ReplaceAll(text, atFilename, highlightStyle.Render(atFilename))
225+
highlight := base.Foreground(t.Secondary())
226+
start, end := filePart.Source.Text.Start, filePart.Source.Text.End
227+
228+
if start > lastEnd {
229+
result.WriteString(base.Render(text[lastEnd:start]))
230+
}
231+
result.WriteString(highlight.Render(text[start:end]))
232+
233+
lastEnd = end
234+
}
235+
236+
if lastEnd < int64(len(text)) {
237+
result.WriteString(base.Render(text[lastEnd:]))
226238
}
227239

228-
content = base.Width(width - 6).Render(text)
240+
content = base.Width(width - 6).Render(result.String())
229241
}
230242

231243
timestamp := ts.

0 commit comments

Comments
 (0)