use requestAnimationFrame for search
This commit is contained in:
parent
bf13da9178
commit
9b6d75b560
1 changed files with 27 additions and 23 deletions
|
@ -92,9 +92,12 @@ const deepestNodeOpened = (path, options) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchFiles = (query, parent, currentFile) => {
|
const searchFiles = (query, parent, currentFile) => {
|
||||||
|
// Prevent blocking the main thread
|
||||||
|
requestAnimationFrame(() => {
|
||||||
const children = parent.querySelectorAll("li");
|
const children = parent.querySelectorAll("li");
|
||||||
|
|
||||||
if (query === "") {
|
const normalizedQuery = query.toLowerCase().trim();
|
||||||
|
if (normalizedQuery === "") {
|
||||||
children.forEach((item) => {
|
children.forEach((item) => {
|
||||||
item.style.display = "";
|
item.style.display = "";
|
||||||
if (
|
if (
|
||||||
|
@ -104,19 +107,20 @@ const searchFiles = (query, parent, currentFile) => {
|
||||||
item.classList.add("collapsed");
|
item.classList.add("collapsed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uncollapse(currentFile);
|
uncollapse(currentFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const item of children) {
|
for (const item of children) {
|
||||||
if (item.innerText.toLowerCase().includes(query.toLowerCase())) {
|
const matches = item.innerText.toLowerCase().includes(normalizedQuery);
|
||||||
|
if (matches) {
|
||||||
item.style.display = "";
|
item.style.display = "";
|
||||||
uncollapse(item);
|
uncollapse(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
item.style.display = "none";
|
item.style.display = "none";
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
|
|
Loading…
Reference in a new issue