@@ -45,26 +45,33 @@ const TY_KEYWORD = itemTypes.indexOf("keyword");
45
45
46
46
// In the search display, allows to switch between tabs.
47
47
function printTab ( nb ) {
48
- if ( nb === 0 || nb === 1 || nb === 2 ) {
49
- searchState . currentTab = nb ;
50
- }
51
- let nb_copy = nb ;
48
+ let iter = 0 ;
49
+ let foundCurrentTab = false ;
50
+ let foundCurrentResultSet = false ;
52
51
onEachLazy ( document . getElementById ( "titles" ) . childNodes , elem => {
53
- if ( nb_copy === 0 ) {
52
+ if ( nb === iter ) {
54
53
addClass ( elem , "selected" ) ;
54
+ foundCurrentTab = true ;
55
55
} else {
56
56
removeClass ( elem , "selected" ) ;
57
57
}
58
- nb_copy - = 1 ;
58
+ iter + = 1 ;
59
59
} ) ;
60
+ iter = 0 ;
60
61
onEachLazy ( document . getElementById ( "results" ) . childNodes , elem => {
61
- if ( nb === 0 ) {
62
+ if ( nb === iter ) {
62
63
addClass ( elem , "active" ) ;
64
+ foundCurrentResultSet = true ;
63
65
} else {
64
66
removeClass ( elem , "active" ) ;
65
67
}
66
- nb - = 1 ;
68
+ iter + = 1 ;
67
69
} ) ;
70
+ if ( foundCurrentTab && foundCurrentResultSet ) {
71
+ searchState . currentTab = nb ;
72
+ } else if ( nb != 0 ) {
73
+ printTab ( 0 ) ;
74
+ }
68
75
}
69
76
70
77
/**
@@ -1409,18 +1416,12 @@ window.initSearch = rawSearchIndex => {
1409
1416
for ( i = 0 , nSearchWords = searchWords . length ; i < nSearchWords ; ++ i ) {
1410
1417
row = searchIndex [ i ] ;
1411
1418
in_returned = checkReturned ( row , elem , parsedQuery . typeFilter ) ;
1412
- addIntoResults ( results_returned , row . id , i , - 1 , in_returned ) ;
1419
+ addIntoResults ( results_others , row . id , i , - 1 , in_returned ) ;
1413
1420
}
1414
1421
}
1415
1422
} else if ( parsedQuery . foundElems > 0 ) {
1416
- let container = results_others ;
1417
- // In the special case where only a "returned" information is available, we want to
1418
- // put the information into the "results_returned" dict.
1419
- if ( parsedQuery . returned . length !== 0 && parsedQuery . elems . length === 0 ) {
1420
- container = results_returned ;
1421
- }
1422
1423
for ( i = 0 , nSearchWords = searchWords . length ; i < nSearchWords ; ++ i ) {
1423
- handleArgs ( searchIndex [ i ] , i , container ) ;
1424
+ handleArgs ( searchIndex [ i ] , i , results_others ) ;
1424
1425
}
1425
1426
}
1426
1427
}
@@ -1725,12 +1726,26 @@ window.initSearch = rawSearchIndex => {
1725
1726
`${ typeFilter } </h1> in ${ crates } </div>` ;
1726
1727
if ( results . query . error !== null ) {
1727
1728
output += `<h3>Query parser error: "${ results . query . error } ".</h3>` ;
1729
+ output += '<div id="titles">' +
1730
+ makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1731
+ "</div>" ;
1732
+ currentTab = 0 ;
1733
+ } else if ( results . query . foundElems <= 1 && results . query . returned . length === 0 ) {
1734
+ output += `<div id="titles">` +
1735
+ makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1736
+ makeTabHeader ( 1 , "In Parameters" , ret_in_args [ 1 ] ) +
1737
+ makeTabHeader ( 2 , "In Return Types" , ret_returned [ 1 ] ) +
1738
+ "</div>" ;
1739
+ } else {
1740
+ const signatureTabTitle =
1741
+ results . query . elems . length === 0 ? "In Function Return Types" :
1742
+ results . query . returned . length === 0 ? "In Function Parameters" :
1743
+ "In Function Signatures" ;
1744
+ output += '<div id="titles">' +
1745
+ makeTabHeader ( 0 , signatureTabTitle , ret_others [ 1 ] ) +
1746
+ "</div>" ;
1747
+ currentTab = 0 ;
1728
1748
}
1729
- output += `<div id="titles">` +
1730
- makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1731
- makeTabHeader ( 1 , "In Parameters" , ret_in_args [ 1 ] ) +
1732
- makeTabHeader ( 2 , "In Return Types" , ret_returned [ 1 ] ) +
1733
- "</div>" ;
1734
1749
1735
1750
const resultsElem = document . createElement ( "div" ) ;
1736
1751
resultsElem . id = "results" ;
@@ -1745,12 +1760,16 @@ window.initSearch = rawSearchIndex => {
1745
1760
}
1746
1761
search . appendChild ( resultsElem ) ;
1747
1762
// Reset focused elements.
1748
- searchState . focusedByTab = [ null , null , null ] ;
1749
1763
searchState . showResults ( search ) ;
1750
1764
const elems = document . getElementById ( "titles" ) . childNodes ;
1751
- elems [ 0 ] . onclick = ( ) => { printTab ( 0 ) ; } ;
1752
- elems [ 1 ] . onclick = ( ) => { printTab ( 1 ) ; } ;
1753
- elems [ 2 ] . onclick = ( ) => { printTab ( 2 ) ; } ;
1765
+ searchState . focusedByTab = [ ] ;
1766
+ let i = 0 ;
1767
+ for ( const elem of elems ) {
1768
+ const j = i ;
1769
+ elem . onclick = ( ) => { printTab ( j ) ; } ;
1770
+ searchState . focusedByTab . push ( null ) ;
1771
+ i += 1 ;
1772
+ }
1754
1773
printTab ( currentTab ) ;
1755
1774
}
1756
1775
0 commit comments