Vanessa 2025-01-17 18:16:55 +08:00
parent 81950fa52d
commit cee6d444d7

View file

@ -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"]');