@@ -218,12 +218,14 @@ if (!String.prototype.endsWith) {
218
218
//
219
219
// So I guess you could say things are getting pretty interoperable.
220
220
function getVirtualKey ( ev ) {
221
- if ( "key" in ev && typeof ev . key != "undefined" )
221
+ if ( "key" in ev && typeof ev . key != "undefined" ) {
222
222
return ev . key ;
223
+ }
223
224
224
225
var c = ev . charCode || ev . keyCode ;
225
- if ( c == 27 )
226
+ if ( c == 27 ) {
226
227
return "Escape" ;
228
+ }
227
229
return String . fromCharCode ( c ) ;
228
230
}
229
231
@@ -431,12 +433,13 @@ if (!String.prototype.endsWith) {
431
433
432
434
/**
433
435
* Executes the query and builds an index of results
434
- * @param {[Object] } query [The user query]
435
- * @param {[type] } searchWords [The list of search words to query
436
- * against]
437
- * @return {[type] } [A search index of results]
436
+ * @param {[Object] } query [The user query]
437
+ * @param {[type] } searchWords [The list of search words to query
438
+ * against]
439
+ * @param {[type] } filterCrates [Crate to search in if defined]
440
+ * @return {[type] } [A search index of results]
438
441
*/
439
- function execQuery ( query , searchWords ) {
442
+ function execQuery ( query , searchWords , filterCrates ) {
440
443
function itemTypeFromName ( typename ) {
441
444
for ( var i = 0 ; i < itemTypes . length ; ++ i ) {
442
445
if ( itemTypes [ i ] === typename ) {
@@ -812,6 +815,9 @@ if (!String.prototype.endsWith) {
812
815
{
813
816
val = extractGenerics ( val . substr ( 1 , val . length - 2 ) ) ;
814
817
for ( var i = 0 ; i < nSearchWords ; ++ i ) {
818
+ if ( filterCrates !== undefined && searchIndex [ i ] . crate !== filterCrates ) {
819
+ continue ;
820
+ }
815
821
var in_args = findArg ( searchIndex [ i ] , val , true ) ;
816
822
var returned = checkReturned ( searchIndex [ i ] , val , true ) ;
817
823
var ty = searchIndex [ i ] ;
@@ -866,6 +872,9 @@ if (!String.prototype.endsWith) {
866
872
var output = extractGenerics ( parts [ 1 ] ) ;
867
873
868
874
for ( var i = 0 ; i < nSearchWords ; ++ i ) {
875
+ if ( filterCrates !== undefined && searchIndex [ i ] . crate !== filterCrates ) {
876
+ continue ;
877
+ }
869
878
var type = searchIndex [ i ] . type ;
870
879
var ty = searchIndex [ i ] ;
871
880
if ( ! type ) {
@@ -937,11 +946,11 @@ if (!String.prototype.endsWith) {
937
946
var contains = paths . slice ( 0 , paths . length > 1 ? paths . length - 1 : 1 ) ;
938
947
939
948
for ( j = 0 ; j < nSearchWords ; ++ j ) {
940
- var lev_distance ;
941
949
var ty = searchIndex [ j ] ;
942
- if ( ! ty ) {
950
+ if ( ! ty || ( filterCrates !== undefined && ty . crate !== filterCrates ) ) {
943
951
continue ;
944
952
}
953
+ var lev_distance ;
945
954
var lev_add = 0 ;
946
955
if ( paths . length > 1 ) {
947
956
var lev = checkPath ( contains , paths [ paths . length - 1 ] , ty ) ;
@@ -1326,7 +1335,7 @@ if (!String.prototype.endsWith) {
1326
1335
return '<div>' + text + ' <div class="count">(' + nbElems + ')</div></div>' ;
1327
1336
}
1328
1337
1329
- function showResults ( results ) {
1338
+ function showResults ( results , filterCrates ) {
1330
1339
if ( results [ 'others' ] . length === 1 &&
1331
1340
getCurrentValue ( 'rustdoc-go-to-only-result' ) === "true" ) {
1332
1341
var elem = document . createElement ( 'a' ) ;
@@ -1344,8 +1353,13 @@ if (!String.prototype.endsWith) {
1344
1353
var ret_in_args = addTab ( results [ 'in_args' ] , query , false ) ;
1345
1354
var ret_returned = addTab ( results [ 'returned' ] , query , false ) ;
1346
1355
1356
+ var filter = "" ;
1357
+ if ( filterCrates !== undefined ) {
1358
+ filter = " (in <b>" + filterCrates + "</b> crate)" ;
1359
+ }
1360
+
1347
1361
var output = '<h1>Results for ' + escape ( query . query ) +
1348
- ( query . type ? ' (type: ' + escape ( query . type ) + ')' : '' ) + '</h1>' +
1362
+ ( query . type ? ' (type: ' + escape ( query . type ) + ')' : '' ) + filter + '</h1>' +
1349
1363
'<div id="titles">' +
1350
1364
makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1351
1365
makeTabHeader ( 1 , "In Parameters" , ret_in_args [ 1 ] ) +
@@ -1374,7 +1388,7 @@ if (!String.prototype.endsWith) {
1374
1388
printTab ( currentTab ) ;
1375
1389
}
1376
1390
1377
- function execSearch ( query , searchWords ) {
1391
+ function execSearch ( query , searchWords , filterCrates ) {
1378
1392
var queries = query . raw . split ( "," ) ;
1379
1393
var results = {
1380
1394
'in_args' : [ ] ,
@@ -1385,7 +1399,7 @@ if (!String.prototype.endsWith) {
1385
1399
for ( var i = 0 ; i < queries . length ; ++ i ) {
1386
1400
var query = queries [ i ] . trim ( ) ;
1387
1401
if ( query . length !== 0 ) {
1388
- var tmp = execQuery ( getQuery ( query ) , searchWords ) ;
1402
+ var tmp = execQuery ( getQuery ( query ) , searchWords , filterCrates ) ;
1389
1403
1390
1404
results [ 'in_args' ] . push ( tmp [ 'in_args' ] ) ;
1391
1405
results [ 'returned' ] . push ( tmp [ 'returned' ] ) ;
@@ -1447,15 +1461,27 @@ if (!String.prototype.endsWith) {
1447
1461
}
1448
1462
}
1449
1463
1450
- function search ( e ) {
1464
+ function getFilterCrates ( ) {
1465
+ var elem = document . getElementById ( "crate-search" ) ;
1466
+
1467
+ if ( elem && elem . value !== "All crates" && rawSearchIndex . hasOwnProperty ( elem . value ) ) {
1468
+ return elem . value ;
1469
+ }
1470
+ return undefined ;
1471
+ }
1472
+
1473
+ function search ( e , forced ) {
1451
1474
var params = getQueryStringParams ( ) ;
1452
1475
var query = getQuery ( search_input . value . trim ( ) ) ;
1453
1476
1454
1477
if ( e ) {
1455
1478
e . preventDefault ( ) ;
1456
1479
}
1457
1480
1458
- if ( query . query . length === 0 || query . id === currentResults ) {
1481
+ if ( query . query . length === 0 ) {
1482
+ return ;
1483
+ }
1484
+ if ( forced !== true && query . id === currentResults ) {
1459
1485
if ( query . query . length > 0 ) {
1460
1486
putBackSearch ( search_input ) ;
1461
1487
}
@@ -1475,7 +1501,8 @@ if (!String.prototype.endsWith) {
1475
1501
}
1476
1502
}
1477
1503
1478
- showResults ( execSearch ( query , index ) ) ;
1504
+ var filterCrates = getFilterCrates ( ) ;
1505
+ showResults ( execSearch ( query , index , filterCrates ) , filterCrates ) ;
1479
1506
}
1480
1507
1481
1508
function buildIndex ( rawSearchIndex ) {
@@ -1575,6 +1602,13 @@ if (!String.prototype.endsWith) {
1575
1602
} ;
1576
1603
search_input . onpaste = search_input . onchange ;
1577
1604
1605
+ var selectCrate = document . getElementById ( 'crate-search' ) ;
1606
+ if ( selectCrate ) {
1607
+ selectCrate . onchange = function ( ) {
1608
+ search ( undefined , true ) ;
1609
+ } ;
1610
+ }
1611
+
1578
1612
// Push and pop states are used to add search results to the browser
1579
1613
// history.
1580
1614
if ( browserSupportsHistoryApi ( ) ) {
@@ -2323,6 +2357,39 @@ if (!String.prototype.endsWith) {
2323
2357
if ( window . location . hash && window . location . hash . length > 0 ) {
2324
2358
expandSection ( window . location . hash . replace ( / ^ # / , '' ) ) ;
2325
2359
}
2360
+
2361
+ function addSearchOptions ( crates ) {
2362
+ var elem = document . getElementById ( 'crate-search' ) ;
2363
+
2364
+ if ( ! elem ) {
2365
+ return ;
2366
+ }
2367
+ var crates_text = [ ] ;
2368
+ for ( var crate in crates ) {
2369
+ if ( crates . hasOwnProperty ( crate ) ) {
2370
+ crates_text . push ( crate ) ;
2371
+ }
2372
+ }
2373
+ crates_text . sort ( function ( a , b ) {
2374
+ var lower_a = a . toLowerCase ( ) ;
2375
+ var lower_b = b . toLowerCase ( ) ;
2376
+
2377
+ if ( lower_a < lower_b ) {
2378
+ return - 1 ;
2379
+ } else if ( lower_a > lower_b ) {
2380
+ return 1 ;
2381
+ }
2382
+ return 0 ;
2383
+ } ) ;
2384
+ for ( var i = 0 ; i < crates_text . length ; ++ i ) {
2385
+ var option = document . createElement ( "option" ) ;
2386
+ option . value = crates_text [ i ] ;
2387
+ option . innerText = crates_text [ i ] ;
2388
+ elem . appendChild ( option ) ;
2389
+ }
2390
+ }
2391
+
2392
+ window . addSearchOptions = addSearchOptions ;
2326
2393
} ( ) ) ;
2327
2394
2328
2395
// Sets the focus on the search bar at the top of the page
0 commit comments