about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/search.js
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-01-09 12:43:37 +0000
committerbors <bors@rust-lang.org>2022-01-09 12:43:37 +0000
commitf7bb8e3677ba4277914e85a3060e5d69151aed44 (patch)
tree47846c6f667683a6e5736242239cd4f686fa6ecd /src/librustdoc/html/static/js/search.js
parente19ca1d946269f7b7eb13171531caf2e16f42076 (diff)
parente6aa48d3a7984ca928b8de65e544eab18b1605c2 (diff)
downloadrust-f7bb8e3677ba4277914e85a3060e5d69151aed44.tar.gz
rust-f7bb8e3677ba4277914e85a3060e5d69151aed44.zip
Auto merge of #92690 - matthiaskrgr:rollup-rw0oz05, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #92055 (Add release notes for 1.58)
 - #92490 (Move crate drop-down to search results page)
 - #92510 (Don't resolve blocks in foreign functions)
 - #92573 (expand: Refactor InvocationCollector visitor for better code reuse)
 - #92608 (rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes)
 - #92657 (Implemented const casts of raw pointers)
 - #92671 (Make `Atomic*::from_mut` return `&mut Atomic*`)
 - #92673 (Remove useless collapse toggle on "all items" page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src/librustdoc/html/static/js/search.js')
-rw-r--r--src/librustdoc/html/static/js/search.js39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index cf320f7b495..e859431e1f1 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -1085,7 +1085,7 @@ window.initSearch = function(rawSearchIndex) {
         return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>";
     }
 
-    function showResults(results, go_to_first) {
+    function showResults(results, go_to_first, filterCrates) {
         var search = searchState.outputElement();
         if (go_to_first || (results.others.length === 1
             && getSettingValue("go-to-only-result") === "true"
@@ -1126,9 +1126,16 @@ window.initSearch = function(rawSearchIndex) {
             }
         }
 
-        var output = "<h1>Results for " + escape(query.query) +
+        let crates = `<select id="crate-search"><option value="All crates">All crates</option>`;
+        for (let c of window.ALL_CRATES) {
+            crates += `<option value="${c}" ${c == filterCrates && "selected"}>${c}</option>`;
+        }
+        crates += `</select>`;
+        var output = `<div id="search-settings">
+            <h1 class="search-results-title">Results for ${escape(query.query)} ` +
             (query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
-            "<div id=\"titles\">" +
+            ` in ${crates} ` +
+            `</div><div id="titles">` +
             makeTabHeader(0, "In Names", ret_others[1]) +
             makeTabHeader(1, "In Parameters", ret_in_args[1]) +
             makeTabHeader(2, "In Return Types", ret_returned[1]) +
@@ -1141,6 +1148,7 @@ window.initSearch = function(rawSearchIndex) {
         resultsElem.appendChild(ret_returned[0]);
 
         search.innerHTML = output;
+        document.getElementById("crate-search").addEventListener("input", updateCrate);
         search.appendChild(resultsElem);
         // Reset focused elements.
         searchState.focusedByTab = [null, null, null];
@@ -1316,7 +1324,8 @@ window.initSearch = function(rawSearchIndex) {
         }
 
         var filterCrates = getFilterCrates();
-        showResults(execSearch(query, searchWords, filterCrates), params["go_to_first"]);
+        showResults(execSearch(query, searchWords, filterCrates),
+            params["go_to_first"], filterCrates);
     }
 
     function buildIndex(rawSearchIndex) {
@@ -1552,19 +1561,6 @@ window.initSearch = function(rawSearchIndex) {
             }
         });
 
-
-        var selectCrate = document.getElementById("crate-search");
-        if (selectCrate) {
-            selectCrate.onchange = function() {
-                updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
-                // In case you "cut" the entry from the search input, then change the crate filter
-                // before paste back the previous search, you get the old search results without
-                // the filter. To prevent this, we need to remove the previous results.
-                currentResults = null;
-                search(undefined, true);
-            };
-        }
-
         // Push and pop states are used to add search results to the browser
         // history.
         if (searchState.browserSupportsHistoryApi()) {
@@ -1616,6 +1612,15 @@ window.initSearch = function(rawSearchIndex) {
         };
     }
 
+    function updateCrate(ev) {
+        updateLocalStorage("rustdoc-saved-filter-crate", ev.target.value);
+        // In case you "cut" the entry from the search input, then change the crate filter
+        // before paste back the previous search, you get the old search results without
+        // the filter. To prevent this, we need to remove the previous results.
+        currentResults = null;
+        search(undefined, true);
+    }
+
     searchWords = buildIndex(rawSearchIndex);
     registerSearchEvents();
     // If there's a search term in the URL, execute the search now.