@@ -1085,7 +1085,7 @@ window.initSearch = function(rawSearchIndex) {
10851085 return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>" ;
10861086 }
10871087
1088- function showResults ( results , go_to_first ) {
1088+ function showResults ( results , go_to_first , filterCrates ) {
10891089 var search = searchState . outputElement ( ) ;
10901090 if ( go_to_first || ( results . others . length === 1
10911091 && getSettingValue ( "go-to-only-result" ) === "true"
@@ -1126,9 +1126,16 @@ window.initSearch = function(rawSearchIndex) {
11261126 }
11271127 }
11281128
1129- var output = "<h1>Results for " + escape ( query . query ) +
1129+ let crates = `<select id="crate-search"><option value="All crates">All crates</option>` ;
1130+ for ( let c of window . ALL_CRATES ) {
1131+ crates += `<option value="${ c } " ${ c == filterCrates && "selected" } >${ c } </option>` ;
1132+ }
1133+ crates += `</select>` ;
1134+ var output = `<div id="search-settings">
1135+ <h1 class="search-results-title">Results for ${ escape ( query . query ) } ` +
11301136 ( query . type ? " (type: " + escape ( query . type ) + ")" : "" ) + "</h1>" +
1131- "<div id=\"titles\">" +
1137+ ` in ${ crates } ` +
1138+ `</div><div id="titles">` +
11321139 makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
11331140 makeTabHeader ( 1 , "In Parameters" , ret_in_args [ 1 ] ) +
11341141 makeTabHeader ( 2 , "In Return Types" , ret_returned [ 1 ] ) +
@@ -1141,6 +1148,7 @@ window.initSearch = function(rawSearchIndex) {
11411148 resultsElem . appendChild ( ret_returned [ 0 ] ) ;
11421149
11431150 search . innerHTML = output ;
1151+ document . getElementById ( "crate-search" ) . addEventListener ( "input" , updateCrate ) ;
11441152 search . appendChild ( resultsElem ) ;
11451153 // Reset focused elements.
11461154 searchState . focusedByTab = [ null , null , null ] ;
@@ -1316,7 +1324,8 @@ window.initSearch = function(rawSearchIndex) {
13161324 }
13171325
13181326 var filterCrates = getFilterCrates ( ) ;
1319- showResults ( execSearch ( query , searchWords , filterCrates ) , params [ "go_to_first" ] ) ;
1327+ showResults ( execSearch ( query , searchWords , filterCrates ) ,
1328+ params [ "go_to_first" ] , filterCrates ) ;
13201329 }
13211330
13221331 function buildIndex ( rawSearchIndex ) {
@@ -1552,19 +1561,6 @@ window.initSearch = function(rawSearchIndex) {
15521561 }
15531562 } ) ;
15541563
1555-
1556- var selectCrate = document . getElementById ( "crate-search" ) ;
1557- if ( selectCrate ) {
1558- selectCrate . onchange = function ( ) {
1559- updateLocalStorage ( "rustdoc-saved-filter-crate" , selectCrate . value ) ;
1560- // In case you "cut" the entry from the search input, then change the crate filter
1561- // before paste back the previous search, you get the old search results without
1562- // the filter. To prevent this, we need to remove the previous results.
1563- currentResults = null ;
1564- search ( undefined , true ) ;
1565- } ;
1566- }
1567-
15681564 // Push and pop states are used to add search results to the browser
15691565 // history.
15701566 if ( searchState . browserSupportsHistoryApi ( ) ) {
@@ -1616,6 +1612,15 @@ window.initSearch = function(rawSearchIndex) {
16161612 } ;
16171613 }
16181614
1615+ function updateCrate ( ev ) {
1616+ updateLocalStorage ( "rustdoc-saved-filter-crate" , ev . target . value ) ;
1617+ // In case you "cut" the entry from the search input, then change the crate filter
1618+ // before paste back the previous search, you get the old search results without
1619+ // the filter. To prevent this, we need to remove the previous results.
1620+ currentResults = null ;
1621+ search ( undefined , true ) ;
1622+ }
1623+
16191624 searchWords = buildIndex ( rawSearchIndex ) ;
16201625 registerSearchEvents ( ) ;
16211626 // If there's a search term in the URL, execute the search now.
0 commit comments