Commit 7afe7de4f0

Austin Rude <rudedogg@users.noreply.github.com>
2022-08-06 05:45:46
autodoc: only modify the DOM once to display the search results
1 parent 40babaa
Changed files (1)
lib
docs
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");