From 9f463fec1ef79f04db99a97934991a193ad5d4d7 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 5 Dec 2022 21:36:33 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/6790 --- app/src/protyle/markdown/highlightRender.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/markdown/highlightRender.ts b/app/src/protyle/markdown/highlightRender.ts index 2d506f338..bebeaa742 100644 --- a/app/src/protyle/markdown/highlightRender.ts +++ b/app/src/protyle/markdown/highlightRender.ts @@ -2,6 +2,7 @@ import {addScript} from "../util/addScript"; import {Constants} from "../../constants"; import {focusByOffset} from "../util/selection"; import {setCodeTheme} from "../../util/assets"; +import {hasClosestByClassName} from "../util/hasClosest"; export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) => { let codeElements: NodeListOf; @@ -98,10 +99,13 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) = languageElement.style.marginLeft = ""; } } - const matchElement = block.querySelector('span[data-type="search-mark"]'); - if (matchElement) { - // 搜索定位 - matchElement.scrollIntoView(); + // 搜索定位 + const layoutElement = hasClosestByClassName(block, "search__layout", true) + if (layoutElement && block.parentElement.getAttribute("data-node-id") === layoutElement.querySelector("#searchList > .b3-list-item--focus")?.getAttribute("data-node-id")) { + const matchElement = block.querySelector('span[data-type="search-mark"]'); + if (matchElement) { + matchElement.scrollIntoView(); + } } block.innerHTML = hljs.highlight( block.textContent + (block.textContent.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609