File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
packages/tui/internal/components/chat Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff 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 .
You can’t perform that action at this time.
0 commit comments