From 1a20840a2a0e48f33fd2f706211768b3d29e68d1 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 16 Aug 2024 21:46:25 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/10769 --- app/src/util/highlightById.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.ts index d069606b8..4b1e3fee2 100644 --- a/app/src/util/highlightById.ts +++ b/app/src/util/highlightById.ts @@ -47,9 +47,7 @@ export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = fal if (blockElement.classList.contains("code-block")) { const brElement = document.createElement('br'); range.insertNode(brElement); - brElement.scrollIntoView({ - block: 'end', - }); + brElement.scrollIntoView({block: "center", behavior}); brElement.remove(); return; } @@ -58,8 +56,11 @@ export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = fal (blockElement.querySelector(".av__row--header").getAttribute("style")?.indexOf("transform") > -1 || blockElement.querySelector(".av__row--footer").getAttribute("style")?.indexOf("transform") > -1)) { return; } + + const br2Element = document.createElement('br'); + range.insertNode(br2Element); const editorElement = protyle.contentElement; - const cursorTop = getSelectionPosition(editorElement).top - editorElement.getBoundingClientRect().top; + const cursorTop = br2Element.getBoundingClientRect().top - editorElement.getBoundingClientRect().top; let scrollTop = 0; if (cursorTop < 0) { scrollTop = editorElement.scrollTop + cursorTop; @@ -69,6 +70,7 @@ export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = fal if (scrollTop !== 0) { editorElement.scroll({top: scrollTop, behavior}); } + br2Element.remove(); return; } }