@@ -214,12 +214,14 @@ if (!String.prototype.endsWith) {
214
214
//
215
215
// So I guess you could say things are getting pretty interoperable.
216
216
function getVirtualKey ( ev ) {
217
- if ( "key" in ev && typeof ev . key != "undefined" )
217
+ if ( "key" in ev && typeof ev . key != "undefined" ) {
218
218
return ev . key ;
219
+ }
219
220
220
221
var c = ev . charCode || ev . keyCode ;
221
- if ( c == 27 )
222
+ if ( c == 27 ) {
222
223
return "Escape" ;
224
+ }
223
225
return String . fromCharCode ( c ) ;
224
226
}
225
227
@@ -427,12 +429,13 @@ if (!String.prototype.endsWith) {
427
429
428
430
/**
429
431
* Executes the query and builds an index of results
430
- * @param {[Object] } query [The user query]
431
- * @param {[type] } searchWords [The list of search words to query
432
- * against]
433
- * @return {[type] } [A search index of results]
432
+ * @param {[Object] } query [The user query]
433
+ * @param {[type] } searchWords [The list of search words to query
434
+ * against]
435
+ * @param {[type] } filterCrates [Crate to search in if defined]
436
+ * @return {[type] } [A search index of results]
434
437
*/
435
- function execQuery ( query , searchWords ) {
438
+ function execQuery ( query , searchWords , filterCrates ) {
436
439
function itemTypeFromName ( typename ) {
437
440
for ( var i = 0 ; i < itemTypes . length ; ++ i ) {
438
441
if ( itemTypes [ i ] === typename ) {
@@ -808,6 +811,9 @@ if (!String.prototype.endsWith) {
808
811
{
809
812
val = extractGenerics ( val . substr ( 1 , val . length - 2 ) ) ;
810
813
for ( var i = 0 ; i < nSearchWords ; ++ i ) {
814
+ if ( filterCrates !== undefined && searchIndex [ i ] . crate !== filterCrates ) {
815
+ continue ;
816
+ }
811
817
var in_args = findArg ( searchIndex [ i ] , val , true ) ;
812
818
var returned = checkReturned ( searchIndex [ i ] , val , true ) ;
813
819
var ty = searchIndex [ i ] ;
@@ -862,6 +868,9 @@ if (!String.prototype.endsWith) {
862
868
var output = extractGenerics ( parts [ 1 ] ) ;
863
869
864
870
for ( var i = 0 ; i < nSearchWords ; ++ i ) {
871
+ if ( filterCrates !== undefined && searchIndex [ i ] . crate !== filterCrates ) {
872
+ continue ;
873
+ }
865
874
var type = searchIndex [ i ] . type ;
866
875
var ty = searchIndex [ i ] ;
867
876
if ( ! type ) {
@@ -933,11 +942,11 @@ if (!String.prototype.endsWith) {
933
942
var contains = paths . slice ( 0 , paths . length > 1 ? paths . length - 1 : 1 ) ;
934
943
935
944
for ( j = 0 ; j < nSearchWords ; ++ j ) {
936
- var lev_distance ;
937
945
var ty = searchIndex [ j ] ;
938
- if ( ! ty ) {
946
+ if ( ! ty || ( filterCrates !== undefined && ty . crate !== filterCrates ) ) {
939
947
continue ;
940
948
}
949
+ var lev_distance ;
941
950
var lev_add = 0 ;
942
951
if ( paths . length > 1 ) {
943
952
var lev = checkPath ( contains , paths [ paths . length - 1 ] , ty ) ;
@@ -1322,7 +1331,7 @@ if (!String.prototype.endsWith) {
1322
1331
return '<div>' + text + ' <div class="count">(' + nbElems + ')</div></div>' ;
1323
1332
}
1324
1333
1325
- function showResults ( results ) {
1334
+ function showResults ( results , filterCrates ) {
1326
1335
if ( results [ 'others' ] . length === 1 &&
1327
1336
getCurrentValue ( 'rustdoc-go-to-only-result' ) === "true" ) {
1328
1337
var elem = document . createElement ( 'a' ) ;
@@ -1340,8 +1349,13 @@ if (!String.prototype.endsWith) {
1340
1349
var ret_in_args = addTab ( results [ 'in_args' ] , query , false ) ;
1341
1350
var ret_returned = addTab ( results [ 'returned' ] , query , false ) ;
1342
1351
1352
+ var filter = "" ;
1353
+ if ( filterCrates !== undefined ) {
1354
+ filter = " (in <b>" + filterCrates + "</b> crate)" ;
1355
+ }
1356
+
1343
1357
var output = '<h1>Results for ' + escape ( query . query ) +
1344
- ( query . type ? ' (type: ' + escape ( query . type ) + ')' : '' ) + '</h1>' +
1358
+ ( query . type ? ' (type: ' + escape ( query . type ) + ')' : '' ) + filter + '</h1>' +
1345
1359
'<div id="titles">' +
1346
1360
makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1347
1361
makeTabHeader ( 1 , "In Parameters" , ret_in_args [ 1 ] ) +
@@ -1370,7 +1384,7 @@ if (!String.prototype.endsWith) {
1370
1384
printTab ( currentTab ) ;
1371
1385
}
1372
1386
1373
- function execSearch ( query , searchWords ) {
1387
+ function execSearch ( query , searchWords , filterCrates ) {
1374
1388
var queries = query . raw . split ( "," ) ;
1375
1389
var results = {
1376
1390
'in_args' : [ ] ,
@@ -1381,7 +1395,7 @@ if (!String.prototype.endsWith) {
1381
1395
for ( var i = 0 ; i < queries . length ; ++ i ) {
1382
1396
var query = queries [ i ] . trim ( ) ;
1383
1397
if ( query . length !== 0 ) {
1384
- var tmp = execQuery ( getQuery ( query ) , searchWords ) ;
1398
+ var tmp = execQuery ( getQuery ( query ) , searchWords , filterCrates ) ;
1385
1399
1386
1400
results [ 'in_args' ] . push ( tmp [ 'in_args' ] ) ;
1387
1401
results [ 'returned' ] . push ( tmp [ 'returned' ] ) ;
@@ -1443,15 +1457,27 @@ if (!String.prototype.endsWith) {
1443
1457
}
1444
1458
}
1445
1459
1446
- function search ( e ) {
1460
+ function getFilterCrates ( ) {
1461
+ var elem = document . getElementById ( "crate-search" ) ;
1462
+
1463
+ if ( elem && elem . value !== "All crates" && rawSearchIndex . hasOwnProperty ( elem . value ) ) {
1464
+ return elem . value ;
1465
+ }
1466
+ return undefined ;
1467
+ }
1468
+
1469
+ function search ( e , forced ) {
1447
1470
var params = getQueryStringParams ( ) ;
1448
1471
var query = getQuery ( search_input . value . trim ( ) ) ;
1449
1472
1450
1473
if ( e ) {
1451
1474
e . preventDefault ( ) ;
1452
1475
}
1453
1476
1454
- if ( query . query . length === 0 || query . id === currentResults ) {
1477
+ if ( query . query . length === 0 ) {
1478
+ return ;
1479
+ }
1480
+ if ( forced !== true && query . id === currentResults ) {
1455
1481
if ( query . query . length > 0 ) {
1456
1482
putBackSearch ( search_input ) ;
1457
1483
}
@@ -1471,7 +1497,8 @@ if (!String.prototype.endsWith) {
1471
1497
}
1472
1498
}
1473
1499
1474
- showResults ( execSearch ( query , index ) ) ;
1500
+ var filterCrates = getFilterCrates ( ) ;
1501
+ showResults ( execSearch ( query , index , filterCrates ) , filterCrates ) ;
1475
1502
}
1476
1503
1477
1504
function buildIndex ( rawSearchIndex ) {
@@ -1571,6 +1598,13 @@ if (!String.prototype.endsWith) {
1571
1598
} ;
1572
1599
search_input . onpaste = search_input . onchange ;
1573
1600
1601
+ var selectCrate = document . getElementById ( 'crate-search' ) ;
1602
+ if ( selectCrate ) {
1603
+ selectCrate . onchange = function ( ) {
1604
+ search ( undefined , true ) ;
1605
+ } ;
1606
+ }
1607
+
1574
1608
// Push and pop states are used to add search results to the browser
1575
1609
// history.
1576
1610
if ( browserSupportsHistoryApi ( ) ) {
@@ -2319,6 +2353,39 @@ if (!String.prototype.endsWith) {
2319
2353
if ( window . location . hash && window . location . hash . length > 0 ) {
2320
2354
expandSection ( window . location . hash . replace ( / ^ # / , '' ) ) ;
2321
2355
}
2356
+
2357
+ function addSearchOptions ( crates ) {
2358
+ var elem = document . getElementById ( 'crate-search' ) ;
2359
+
2360
+ if ( ! elem ) {
2361
+ return ;
2362
+ }
2363
+ var crates_text = [ ] ;
2364
+ for ( var crate in crates ) {
2365
+ if ( crates . hasOwnProperty ( crate ) ) {
2366
+ crates_text . push ( crate ) ;
2367
+ }
2368
+ }
2369
+ crates_text . sort ( function ( a , b ) {
2370
+ var lower_a = a . toLowerCase ( ) ;
2371
+ var lower_b = b . toLowerCase ( ) ;
2372
+
2373
+ if ( lower_a < lower_b ) {
2374
+ return - 1 ;
2375
+ } else if ( lower_a > lower_b ) {
2376
+ return 1 ;
2377
+ }
2378
+ return 0 ;
2379
+ } ) ;
2380
+ for ( var i = 0 ; i < crates_text . length ; ++ i ) {
2381
+ var option = document . createElement ( "option" ) ;
2382
+ option . value = crates_text [ i ] ;
2383
+ option . innerText = crates_text [ i ] ;
2384
+ elem . appendChild ( option ) ;
2385
+ }
2386
+ }
2387
+
2388
+ window . addSearchOptions = addSearchOptions ;
2322
2389
} ( ) ) ;
2323
2390
2324
2391
// Sets the focus on the search bar at the top of the page
0 commit comments