1- import { MarkdownRenderer } from "@features/editor/components/MarkdownRenderer" ;
1+ import {
2+ baseComponents ,
3+ MarkdownRenderer ,
4+ remarkPlugins ,
5+ } from "@features/editor/components/MarkdownRenderer" ;
26import { File } from "@phosphor-icons/react" ;
3- import { Box , Code } from "@radix-ui/themes" ;
7+ import { Box , Code , Text } from "@radix-ui/themes" ;
48import type { ReactNode } from "react" ;
9+ import { memo } from "react" ;
10+ import type { Components } from "react-markdown" ;
11+ import ReactMarkdown from "react-markdown" ;
512
613interface UserMessageProps {
714 content : string ;
815}
916
17+ /**
18+ * Markdown components that render paragraphs as inline spans so that
19+ * text chunks between file mentions stay on the same line.
20+ */
21+ const inlineComponents : Components = {
22+ ...baseComponents ,
23+ p : ( { children } ) => (
24+ < Text as = "span" size = "1" color = "gray" highContrast >
25+ { children }
26+ </ Text >
27+ ) ,
28+ } ;
29+
30+ const InlineMarkdown = memo ( function InlineMarkdown ( {
31+ content,
32+ } : {
33+ content : string ;
34+ } ) {
35+ return (
36+ < ReactMarkdown remarkPlugins = { remarkPlugins } components = { inlineComponents } >
37+ { content }
38+ </ ReactMarkdown >
39+ ) ;
40+ } ) ;
41+
1042function parseFileMentions ( content : string ) : ReactNode [ ] {
1143 const fileTagRegex = / < f i l e \s + p a t h = " ( [ ^ " ] + ) " \s * \/ > / g;
1244 const parts : ReactNode [ ] = [ ] ;
@@ -16,7 +48,7 @@ function parseFileMentions(content: string): ReactNode[] {
1648 if ( match . index !== undefined && match . index > lastIndex ) {
1749 const textBefore = content . slice ( lastIndex , match . index ) ;
1850 parts . push (
19- < MarkdownRenderer key = { `text-${ lastIndex } ` } content = { textBefore } /> ,
51+ < InlineMarkdown key = { `text-${ lastIndex } ` } content = { textBefore } /> ,
2052 ) ;
2153 }
2254
@@ -32,6 +64,7 @@ function parseFileMentions(content: string): ReactNode[] {
3264 alignItems : "center" ,
3365 gap : "4px" ,
3466 verticalAlign : "middle" ,
67+ margin : "0 6px" ,
3568 } }
3669 >
3770 < File size = { 12 } />
@@ -44,7 +77,7 @@ function parseFileMentions(content: string): ReactNode[] {
4477
4578 if ( lastIndex < content . length ) {
4679 parts . push (
47- < MarkdownRenderer
80+ < InlineMarkdown
4881 key = { `text-${ lastIndex } ` }
4982 content = { content . slice ( lastIndex ) }
5083 /> ,
0 commit comments