mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(chat): render Code Mode execute calls with a dedicated card
This commit is contained in:
1 parent
9075ab1101
commit
f67c3e33b2
6 files changed
+572
-58
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { useMemo, type ReactNode } from 'react'
|
||||
import { detectFileReferences } from '@/lib/fileReferences'
|
||||
|
||||
interface FileReferenceTextProps {
|
||||
text: string
|
||||
onFileClick?: (filePath: string) => void
|
||||
}
|
||||
|
||||
export function FileReferenceText({ text, onFileClick }: FileReferenceTextProps) {
|
||||
const parts = useMemo(() => {
|
||||
const references = detectFileReferences(text)
|
||||
if (references.length === 0) return text
|
||||
|
||||
const segments: ReactNode[] = []
|
||||
let lastIndex = 0
|
||||
|
||||
references.forEach((ref, index) => {
|
||||
if (ref.startIndex > lastIndex) {
|
||||
segments.push(text.slice(lastIndex, ref.startIndex))
|
||||
}
|
||||
|
||||
segments.push(
|
||||
<span
|
||||
key={`ref-${index}`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onFileClick?.(ref.filePath)
|
||||
}}
|
||||
className="text-primary hover:text-primary-hover cursor-pointer underline decoration-dotted"
|
||||
title={`Click to open ${ref.filePath}`}
|
||||
>
|
||||
{ref.fullMatch}
|
||||
</span>,
|
||||
)
|
||||
|
||||
lastIndex = ref.endIndex
|
||||
})
|
||||
|
||||
if (lastIndex < text.length) {
|
||||
segments.push(text.slice(lastIndex))
|
||||
}
|
||||
|
||||
return segments
|
||||
}, [text, onFileClick])
|
||||
|
||||
return <>{parts}</>
|
||||
}
|
||||
Reference in new issue
Block a user