forked from XiaoMo/ChatGPT-Next-Web
fixup
This commit is contained in:
parent
e509749421
commit
220c622f8f
@ -71,22 +71,35 @@ export function Markdown(
|
|||||||
const parent = props.parentRef.current;
|
const parent = props.parentRef.current;
|
||||||
const md = mdRef.current;
|
const md = mdRef.current;
|
||||||
|
|
||||||
if (parent && md) {
|
const checkInView = () => {
|
||||||
const parentBounds = parent.getBoundingClientRect();
|
if (parent && md) {
|
||||||
const twoScreenHeight = Math.max(500, parentBounds.height * 2);
|
const parentBounds = parent.getBoundingClientRect();
|
||||||
const mdBounds = md.getBoundingClientRect();
|
const twoScreenHeight = Math.max(500, parentBounds.height * 2);
|
||||||
const isInRange = (x: number) =>
|
const mdBounds = md.getBoundingClientRect();
|
||||||
x <= parentBounds.bottom + twoScreenHeight &&
|
const isInRange = (x: number) =>
|
||||||
x >= parentBounds.top - twoScreenHeight;
|
x <= parentBounds.bottom + twoScreenHeight &&
|
||||||
inView.current = isInRange(mdBounds.top) || isInRange(mdBounds.bottom);
|
x >= parentBounds.top - twoScreenHeight;
|
||||||
}
|
inView.current = isInRange(mdBounds.top) || isInRange(mdBounds.bottom);
|
||||||
|
}
|
||||||
|
|
||||||
if (inView.current && md) {
|
if (inView.current && md) {
|
||||||
renderedHeight.current = Math.max(
|
renderedHeight.current = Math.max(
|
||||||
renderedHeight.current,
|
renderedHeight.current,
|
||||||
md.getBoundingClientRect().height,
|
md.getBoundingClientRect().height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!inView.current) {
|
||||||
|
checkInView();
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
checkInView();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
Loading…
Reference in New Issue
Block a user