From f8b6ce02abf8629460ef740ba81ebf01e212e909 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 5 Jul 2023 09:22:26 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/8674 --- app/src/util/highlightById.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.ts index 2ef26f613..2262fcfc3 100644 --- a/app/src/util/highlightById.ts +++ b/app/src/util/highlightById.ts @@ -67,15 +67,21 @@ export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = fal offsetTop += (parentNodeElement as HTMLElement).offsetTop; parentNodeElement = parentNodeElement.parentElement; } + let contentTop = 0; + let topElement = protyle.element.firstElementChild + while (topElement && !topElement.classList.contains("protyle-content")) { + contentTop += topElement.clientHeight + topElement = topElement.nextElementSibling; + } if (top) { - protyle.contentElement.scroll({top: offsetTop - 32, behavior}); + protyle.contentElement.scroll({top: offsetTop - contentTop, behavior}); return; } if (protyle.contentElement.scrollTop > offsetTop - 32) { - protyle.contentElement.scroll({top: offsetTop - 32, behavior}); - } else if (protyle.contentElement.scrollTop + protyle.contentElement.clientHeight < offsetTop + nodeElement.clientHeight - 32) { + protyle.contentElement.scroll({top: offsetTop - contentTop, behavior}); + } else if (protyle.contentElement.scrollTop + protyle.contentElement.clientHeight < offsetTop + nodeElement.clientHeight - contentTop) { protyle.contentElement.scroll({ - top: offsetTop + nodeElement.clientHeight - 32 - protyle.contentElement.clientHeight, + top: offsetTop + nodeElement.clientHeight - contentTop - protyle.contentElement.clientHeight, behavior }); }