mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
Fix timing problem on jumping to linked line number in source view
This commit is contained in:
@@ -40,12 +40,7 @@ type Props = {
|
|||||||
permalink?: string;
|
permalink?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SyntaxHighlighter: FC<Props> = ({
|
const SyntaxHighlighter: FC<Props> = ({ language = defaultLanguage, showLineNumbers = true, value, permalink }) => {
|
||||||
language = defaultLanguage,
|
|
||||||
showLineNumbers = true,
|
|
||||||
value,
|
|
||||||
permalink
|
|
||||||
}) => {
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [contentRef, setContentRef] = useState<HTMLElement | null>();
|
const [contentRef, setContentRef] = useState<HTMLElement | null>();
|
||||||
|
|
||||||
@@ -55,7 +50,15 @@ const SyntaxHighlighter: FC<Props> = ({
|
|||||||
const lineNumber = match[1];
|
const lineNumber = match[1];
|
||||||
// We defer the content check until after the syntax-highlighter has rendered
|
// We defer the content check until after the syntax-highlighter has rendered
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const element = contentRef.querySelector(`#line-${lineNumber}`);
|
let tries = 0;
|
||||||
|
let element = contentRef.querySelector(`#line-${lineNumber}`);
|
||||||
|
if (!element && tries < 10) {
|
||||||
|
setInterval(() => {
|
||||||
|
tries += 1;
|
||||||
|
element = contentRef.querySelector(`#line-${lineNumber}`);
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
if (element && element.scrollIntoView) {
|
if (element && element.scrollIntoView) {
|
||||||
element.scrollIntoView();
|
element.scrollIntoView();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user