@@ -45,26 +45,33 @@ const TY_KEYWORD = itemTypes.indexOf("keyword");
4545
4646// In the search display, allows to switch between tabs.
4747function 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 ;
5251 onEachLazy ( document . getElementById ( "titles" ) . childNodes , elem => {
53- if ( nb_copy === 0 ) {
52+ if ( nb === iter ) {
5453 addClass ( elem , "selected" ) ;
54+ foundCurrentTab = true ;
5555 } else {
5656 removeClass ( elem , "selected" ) ;
5757 }
58- nb_copy - = 1 ;
58+ iter + = 1 ;
5959 } ) ;
60+ iter = 0 ;
6061 onEachLazy ( document . getElementById ( "results" ) . childNodes , elem => {
61- if ( nb === 0 ) {
62+ if ( nb === iter ) {
6263 addClass ( elem , "active" ) ;
64+ foundCurrentResultSet = true ;
6365 } else {
6466 removeClass ( elem , "active" ) ;
6567 }
66- nb - = 1 ;
68+ iter + = 1 ;
6769 } ) ;
70+ if ( foundCurrentTab && foundCurrentResultSet ) {
71+ searchState . currentTab = nb ;
72+ } else if ( nb != 0 ) {
73+ printTab ( 0 ) ;
74+ }
6875}
6976
7077/**
@@ -1409,18 +1416,12 @@ window.initSearch = rawSearchIndex => {
14091416 for ( i = 0 , nSearchWords = searchWords . length ; i < nSearchWords ; ++ i ) {
14101417 row = searchIndex [ i ] ;
14111418 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 ) ;
14131420 }
14141421 }
14151422 } 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- }
14221423 for ( i = 0 , nSearchWords = searchWords . length ; i < nSearchWords ; ++ i ) {
1423- handleArgs ( searchIndex [ i ] , i , container ) ;
1424+ handleArgs ( searchIndex [ i ] , i , results_others ) ;
14241425 }
14251426 }
14261427 }
@@ -1725,12 +1726,26 @@ window.initSearch = rawSearchIndex => {
17251726 `${ typeFilter } </h1> in ${ crates } </div>` ;
17261727 if ( results . query . error !== null ) {
17271728 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 ;
17281748 }
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>" ;
17341749
17351750 const resultsElem = document . createElement ( "div" ) ;
17361751 resultsElem . id = "results" ;
@@ -1745,12 +1760,16 @@ window.initSearch = rawSearchIndex => {
17451760 }
17461761 search . appendChild ( resultsElem ) ;
17471762 // Reset focused elements.
1748- searchState . focusedByTab = [ null , null , null ] ;
17491763 searchState . showResults ( search ) ;
17501764 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+ }
17541773 printTab ( currentTab ) ;
17551774 }
17561775
0 commit comments