@@ -6,6 +6,7 @@ import "./mention-chip.css";
66type RenderSegment =
77 | { type : "text" ; text : string }
88 | { type : "link" ; text : string ; href : string }
9+ | { type : "agent" ; text : string }
910 | { type : "mention" ; name : string ; email : string } ;
1011
1112// The plain (not-the-viewer) mention chip look, also used by surfaces that
@@ -35,24 +36,45 @@ export function MentionText({
3536 entries . push ( { segment, key : `${ offset } ` } ) ;
3637 offset += length ;
3738 } ;
39+ const pushText = ( text : string ) => {
40+ let cursor = 0 ;
41+ for ( const match of text . matchAll ( / ( ^ | \s ) ( @ a g e n t ) \b / gi) ) {
42+ const mentionStart = ( match . index ?? 0 ) + match [ 1 ] . length ;
43+ for ( const part of splitLinkSegments (
44+ text . slice ( cursor , mentionStart ) ,
45+ ) ) {
46+ push ( part , part . text . length ) ;
47+ }
48+ push ( { type : "agent" , text : match [ 2 ] } , match [ 2 ] . length ) ;
49+ cursor = mentionStart + match [ 2 ] . length ;
50+ }
51+ for ( const part of splitLinkSegments ( text . slice ( cursor ) ) ) {
52+ push ( part , part . text . length ) ;
53+ }
54+ } ;
3855 for ( const segment of splitMentionSegments ( content ) ) {
3956 if ( segment . type === "mention" ) {
4057 push (
4158 { type : "mention" , name : segment . name , email : segment . email } ,
4259 segment . text . length ,
4360 ) ;
4461 } else {
45- for ( const part of splitLinkSegments ( segment . text ) ) {
46- push ( part , part . text . length ) ;
47- }
62+ pushText ( segment . text ) ;
4863 }
4964 }
5065 return entries ;
5166 } , [ content ] ) ;
5267 const selfEmail = currentUserEmail ?. toLowerCase ( ) ;
5368 return (
54- < span className = { `text-xs ${ className ?? "" } ` } >
69+ < span className = { className } >
5570 { segments . map ( ( { segment, key } ) => {
71+ if ( segment . type === "agent" ) {
72+ return (
73+ < span key = { key } className = { mentionChipClass } >
74+ { segment . text }
75+ </ span >
76+ ) ;
77+ }
5678 if ( segment . type === "mention" ) {
5779 return (
5880 < span
0 commit comments