diff --git a/client/src/pages/ArticleResponse/CodeWithBreadcrumbs.tsx b/client/src/pages/ArticleResponse/CodeWithBreadcrumbs.tsx index d995301810..05a2c7d84a 100644 --- a/client/src/pages/ArticleResponse/CodeWithBreadcrumbs.tsx +++ b/client/src/pages/ArticleResponse/CodeWithBreadcrumbs.tsx @@ -7,9 +7,8 @@ import Code from '../../components/CodeBlock/Code'; type Props = { filePath: string; repoName: string; - onResultClick: (path: string, lines?: [number, number]) => void; + onResultClick: (path: string, lines?: string) => void; startLine: number; - endLine: number; language: string; code: string; }; @@ -19,16 +18,25 @@ const CodeWithBreadcrumbs = ({ repoName, onResultClick, startLine, - endLine, language, code, }: Props) => { - const handleResultClick = useCallback((e: MouseEvent) => { - if (!document.getSelection()?.toString()) { - e.stopPropagation(); - onResultClick(filePath, [Math.max(startLine - 1, 0), endLine - 1]); - } - }, []); + const handleResultClick = useCallback( + (e: MouseEvent) => { + if (!document.getSelection()?.toString()) { + e.stopPropagation(); + onResultClick( + filePath, + startLine + ? `${Math.max(startLine, 0)}_${ + startLine + code.split('\n').length - 1 + }` + : undefined, + ); + } + }, + [filePath, startLine, code, onResultClick], + ); return (
{ ); }, code({ node, inline, className, children, ...props }: CodeProps) { + console.log('className', className); const matchLang = /language-(\w+)/.exec(className || ''); const matchPath = /path:(.+),/.exec(className || ''); const matchLines = /lines:(.+)/.exec(className || ''); @@ -88,17 +89,7 @@ const ArticleResponse = ({ recordId, threadId }: Props) => { code={code} language={matchLang[1]} filePath={matchPath[1]} - onResultClick={() => - openFileModal( - matchPath[1], - lines[0] - 1 - ? `${lines[0] - 1}_${ - lines[0] - 1 + code.split('\n').length - 1 - }` - : undefined, - ) - } - endLine={lines[1] - 1} + onResultClick={openFileModal} startLine={lines[0] - 1} repoName={tab.repoName} />