This commit is contained in:
Vanessa 2024-11-29 07:53:16 +08:00
parent 363bd008cc
commit 18ef49aa4b
4 changed files with 34 additions and 34 deletions

View file

@ -0,0 +1,27 @@
export const searchMarkRender = (protyle: IProtyle, matchElements: NodeListOf<Element>) => {
if (matchElements.length === 0) {
return;
}
protyle.highlight.markHL.clear();
protyle.highlight.markHL.clear();
protyle.highlight.ranges = [];
matchElements.forEach((item, index) => {
const range = new Range();
if (item.getAttribute("data-type") === "search-mark") {
const contentElement = item.firstChild;
item.replaceWith(contentElement);
range.selectNodeContents(contentElement);
} else {
item.setAttribute("data-type", item.getAttribute("data-type").replace(" search-mark", "").replace("search-mark ", ""));
range.selectNodeContents(item);
}
if (index === protyle.highlight.rangeIndex) {
protyle.highlight.markHL.add(range);
} else {
protyle.highlight.mark.add(range);
}
protyle.highlight.ranges.push(range);
});
CSS.highlights.set("search-mark", protyle.highlight.mark);
CSS.highlights.set("search-mark-hl", protyle.highlight.markHL);
};