Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/13826

Vanessacee6d444d76c
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 193abeccc4..d4dd5e50ad 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -1105,15 +1105,25 @@ export const getArticle = (options: {
const contentRect = options.edit.protyle.contentElement.getBoundingClientRect();
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]) {
- if (!options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex].toString()) {
- highlightById(options.edit.protyle, options.id);
+ const highlightKeys = () => {
+ if (options.edit.protyle.highlight.ranges.length > 0 && options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex]) {
+ if (!options.edit.protyle.highlight.ranges[options.edit.protyle.highlight.rangeIndex].toString()) {
+ 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 {
- 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;
+ highlightById(options.edit.protyle, options.id);
}
- } else {
- highlightById(options.edit.protyle, options.id);
}
+ highlightKeys();
+ const observer = new ResizeObserver(() => {
+ highlightKeys();
+ });
+ observer.observe(options.edit.protyle.wysiwyg.element);
+ setTimeout(() => {
+ observer.disconnect();
+ }, Constants.TIMEOUT_COUNT);
});
} else {
const matchElements = options.edit.protyle.wysiwyg.element.querySelectorAll('span[data-type~="search-mark"]');