From 866189bcc0875ba9b695782df901b93a3d4d40db Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 2 Jan 2025 23:23:41 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13703 --- app/src/search/util.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/search/util.ts b/app/src/search/util.ts index 7d99839d6..a04117a5c 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -22,7 +22,7 @@ import {onGet} from "../protyle/util/onGet"; import {addLoading} from "../protyle/ui/initUI"; import {getIconByType} from "../editor/getIcon"; import {unicode2Emoji} from "../emoji"; -import {hasClosestByClassName} from "../protyle/util/hasClosest"; +import {hasClosestBlock, hasClosestByClassName} from "../protyle/util/hasClosest"; import {isIPad, isNotCtrl, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility"; import {newFileByName} from "../util/newFile"; import { @@ -1102,7 +1102,12 @@ export const getArticle = (options: { if (isSupportCSSHL()) { searchMarkRender(options.edit.protyle, getResponse.data.keywords, options.id, () => { if (options.edit.protyle.highlight.ranges.length > 0 && options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex]) { - options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex].getBoundingClientRect().top - contentRect.top - contentRect.height / 2; + const blockElement = hasClosestBlock(options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex].startContainer) + if (blockElement && blockElement.getAttribute("data-node-id") !== options.id) { + highlightById(options.edit.protyle, options.id); + } else { + options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex].getBoundingClientRect().top - contentRect.top - contentRect.height / 2; + } } else { highlightById(options.edit.protyle, options.id); }