@@ -1085,7 +1085,7 @@ window.initSearch = function(rawSearchIndex) {
1085
1085
return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>" ;
1086
1086
}
1087
1087
1088
- function showResults ( results , go_to_first ) {
1088
+ function showResults ( results , go_to_first , filterCrates ) {
1089
1089
var search = searchState . outputElement ( ) ;
1090
1090
if ( go_to_first || ( results . others . length === 1
1091
1091
&& getSettingValue ( "go-to-only-result" ) === "true"
@@ -1126,9 +1126,16 @@ window.initSearch = function(rawSearchIndex) {
1126
1126
}
1127
1127
}
1128
1128
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 ) } ` +
1130
1136
( query . type ? " (type: " + escape ( query . type ) + ")" : "" ) + "</h1>" +
1131
- "<div id=\"titles\">" +
1137
+ ` in ${ crates } ` +
1138
+ `</div><div id="titles">` +
1132
1139
makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1133
1140
makeTabHeader ( 1 , "In Parameters" , ret_in_args [ 1 ] ) +
1134
1141
makeTabHeader ( 2 , "In Return Types" , ret_returned [ 1 ] ) +
@@ -1141,6 +1148,7 @@ window.initSearch = function(rawSearchIndex) {
1141
1148
resultsElem . appendChild ( ret_returned [ 0 ] ) ;
1142
1149
1143
1150
search . innerHTML = output ;
1151
+ document . getElementById ( "crate-search" ) . addEventListener ( "input" , updateCrate ) ;
1144
1152
search . appendChild ( resultsElem ) ;
1145
1153
// Reset focused elements.
1146
1154
searchState . focusedByTab = [ null , null , null ] ;
@@ -1316,7 +1324,8 @@ window.initSearch = function(rawSearchIndex) {
1316
1324
}
1317
1325
1318
1326
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 ) ;
1320
1329
}
1321
1330
1322
1331
function buildIndex ( rawSearchIndex ) {
@@ -1552,19 +1561,6 @@ window.initSearch = function(rawSearchIndex) {
1552
1561
}
1553
1562
} ) ;
1554
1563
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
-
1568
1564
// Push and pop states are used to add search results to the browser
1569
1565
// history.
1570
1566
if ( searchState . browserSupportsHistoryApi ( ) ) {
@@ -1616,6 +1612,15 @@ window.initSearch = function(rawSearchIndex) {
1616
1612
} ;
1617
1613
}
1618
1614
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
+
1619
1624
searchWords = buildIndex ( rawSearchIndex ) ;
1620
1625
registerSearchEvents ( ) ;
1621
1626
// If there's a search term in the URL, execute the search now.
0 commit comments