motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 059713478a06ac15295ead030e95dfc0a205541f (tree)
parent 86d9c3de2b6b43329c16678f1bd7eaddd3d218d7
Author: Loris Cro <kappaloris@gmail.com>
Date:   Sat,  6 Aug 2022 16:43:25 +0200

Merge pull request #12343 from rudedogg/master

autodoc: only modify the DOM once to display the search results
Diffstat:
Mlib/docs/main.js | 29++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/lib/docs/main.js b/lib/docs/main.js @@ -3326,29 +3326,28 @@ var zigAnalysis; } if (matchedItems.length !== 0) { - resizeDomList( - domListSearchResults, - matchedItems.length, - '<li><a href="#"></a></li>' - ); - matchedItems.sort(function (a, b) { let cmp = operatorCompare(b.points, a.points); if (cmp != 0) return cmp; return operatorCompare(a.decl.name, b.decl.name); }); + // Build up the list of search results + let matchedItemsHTML = ""; + for (let i = 0; i < matchedItems.length; i += 1) { - let liDom = domListSearchResults.children[i]; - let aDom = liDom.children[0]; - let match = matchedItems[i]; - let lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1]; - aDom.textContent = lastPkgName + "." + match.path.declNames.join("."); - aDom.setAttribute( - "href", - navLink(match.path.pkgNames, match.path.declNames) - ); + const match = matchedItems[i]; + const lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1]; + + const text = lastPkgName + "." + match.path.declNames.join("."); + const href = navLink(match.path.pkgNames, match.path.declNames); + + matchedItemsHTML += `<li><a href="${href}">${text}</a></li>`; } + + // Replace the search results using our newly constructed HTML string + domListSearchResults.innerHTML = matchedItemsHTML; + renderSearchCursor(); domSectSearchResults.classList.remove("hidden");