Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit c7367a5

Browse files
improve file popup opening at position (#710)
1 parent 786a5a6 commit c7367a5

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

client/src/pages/ArticleResponse/CodeWithBreadcrumbs.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import Code from '../../components/CodeBlock/Code';
77
type Props = {
88
filePath: string;
99
repoName: string;
10-
onResultClick: (path: string, lines?: [number, number]) => void;
10+
onResultClick: (path: string, lines?: string) => void;
1111
startLine: number;
12-
endLine: number;
1312
language: string;
1413
code: string;
1514
};
@@ -19,16 +18,25 @@ const CodeWithBreadcrumbs = ({
1918
repoName,
2019
onResultClick,
2120
startLine,
22-
endLine,
2321
language,
2422
code,
2523
}: Props) => {
26-
const handleResultClick = useCallback((e: MouseEvent) => {
27-
if (!document.getSelection()?.toString()) {
28-
e.stopPropagation();
29-
onResultClick(filePath, [Math.max(startLine - 1, 0), endLine - 1]);
30-
}
31-
}, []);
24+
const handleResultClick = useCallback(
25+
(e: MouseEvent) => {
26+
if (!document.getSelection()?.toString()) {
27+
e.stopPropagation();
28+
onResultClick(
29+
filePath,
30+
startLine
31+
? `${Math.max(startLine, 0)}_${
32+
startLine + code.split('\n').length - 1
33+
}`
34+
: undefined,
35+
);
36+
}
37+
},
38+
[filePath, startLine, code, onResultClick],
39+
);
3240

3341
return (
3442
<div

client/src/pages/ArticleResponse/index.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const ArticleResponse = ({ recordId, threadId }: Props) => {
7575
);
7676
},
7777
code({ node, inline, className, children, ...props }: CodeProps) {
78+
console.log('className', className);
7879
const matchLang = /language-(\w+)/.exec(className || '');
7980
const matchPath = /path:(.+),/.exec(className || '');
8081
const matchLines = /lines:(.+)/.exec(className || '');
@@ -88,17 +89,7 @@ const ArticleResponse = ({ recordId, threadId }: Props) => {
8889
code={code}
8990
language={matchLang[1]}
9091
filePath={matchPath[1]}
91-
onResultClick={() =>
92-
openFileModal(
93-
matchPath[1],
94-
lines[0] - 1
95-
? `${lines[0] - 1}_${
96-
lines[0] - 1 + code.split('\n').length - 1
97-
}`
98-
: undefined,
99-
)
100-
}
101-
endLine={lines[1] - 1}
92+
onResultClick={openFileModal}
10293
startLine={lines[0] - 1}
10394
repoName={tab.repoName}
10495
/>

0 commit comments

Comments
 (0)