mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-10 22:52:34 +01:00
♻️
This commit is contained in:
parent
363bd008cc
commit
18ef49aa4b
4 changed files with 34 additions and 34 deletions
27
app/src/protyle/render/searchMarkRender.ts
Normal file
27
app/src/protyle/render/searchMarkRender.ts
Normal 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);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue