Skip to content

Commit

Permalink
improve file popup opening at position (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 committed Jun 30, 2023
1 parent 786a5a6 commit c7367a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
26 changes: 17 additions & 9 deletions client/src/pages/ArticleResponse/CodeWithBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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 (
<div
Expand Down
13 changes: 2 additions & 11 deletions client/src/pages/ArticleResponse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const ArticleResponse = ({ recordId, threadId }: Props) => {
);
},
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 || '');
Expand All @@ -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}
/>
Expand Down

0 comments on commit c7367a5

Please sign in to comment.