From fe8e3f2bcfcc703ea9dec7c3d85be7d7c8a833ba Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Fri, 5 May 2023 22:59:21 +0800 Subject: [PATCH] fix: #1273 overlap detecting --- app/components/markdown.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 49bb581d..f0e2c723 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -82,10 +82,12 @@ export function Markdown( const parentBounds = parent.getBoundingClientRect(); const twoScreenHeight = Math.max(500, parentBounds.height * 2); const mdBounds = md.getBoundingClientRect(); - const isInRange = (x: number) => - x <= parentBounds.bottom + twoScreenHeight && - x >= parentBounds.top - twoScreenHeight; - inView.current = isInRange(mdBounds.top) || isInRange(mdBounds.bottom); + const parentTop = parentBounds.top - twoScreenHeight; + const parentBottom = parentBounds.bottom + twoScreenHeight; + const isOverlap = + Math.max(parentTop, mdBounds.top) <= + Math.min(parentBottom, mdBounds.bottom); + inView.current = isOverlap; } if (inView.current && md) {