@@ -43,26 +43,33 @@ const TY_KEYWORD = itemTypes.indexOf("keyword");
4343
4444// In the search display, allows to switch between tabs.
4545function printTab ( nb ) {
46- if ( nb === 0 || nb === 1 || nb === 2 ) {
47- searchState . currentTab = nb ;
48- }
49- let nb_copy = nb ;
46+ let iter = 0 ;
47+ let foundCurrentTab = false ;
48+ let foundCurrentResultSet = false ;
5049 onEachLazy ( document . getElementById ( "titles" ) . childNodes , elem => {
51- if ( nb_copy === 0 ) {
50+ if ( nb === iter ) {
5251 addClass ( elem , "selected" ) ;
52+ foundCurrentTab = true ;
5353 } else {
5454 removeClass ( elem , "selected" ) ;
5555 }
56- nb_copy - = 1 ;
56+ iter + = 1 ;
5757 } ) ;
58+ iter = 0 ;
5859 onEachLazy ( document . getElementById ( "results" ) . childNodes , elem => {
59- if ( nb === 0 ) {
60+ if ( nb === iter ) {
6061 addClass ( elem , "active" ) ;
62+ foundCurrentResultSet = true ;
6163 } else {
6264 removeClass ( elem , "active" ) ;
6365 }
64- nb - = 1 ;
66+ iter + = 1 ;
6567 } ) ;
68+ if ( foundCurrentTab && foundCurrentResultSet ) {
69+ searchState . currentTab = nb ;
70+ } else if ( nb != 0 ) {
71+ printTab ( 0 ) ;
72+ }
6673}
6774
6875/**
@@ -1731,6 +1738,7 @@ window.initSearch = rawSearchIndex => {
17311738 output += '<div id="titles">' +
17321739 makeTabHeader ( 0 , signatureTabTitle , ret_others [ 1 ] ) +
17331740 "</div>" ;
1741+ currentTab = 0 ;
17341742 }
17351743
17361744 const resultsElem = document . createElement ( "div" ) ;
@@ -1746,12 +1754,16 @@ window.initSearch = rawSearchIndex => {
17461754 }
17471755 search . appendChild ( resultsElem ) ;
17481756 // Reset focused elements.
1749- searchState . focusedByTab = [ null , null , null ] ;
17501757 searchState . showResults ( search ) ;
17511758 const elems = document . getElementById ( "titles" ) . childNodes ;
1752- elems [ 0 ] . onclick = ( ) => { printTab ( 0 ) ; } ;
1753- elems [ 1 ] . onclick = ( ) => { printTab ( 1 ) ; } ;
1754- elems [ 2 ] . onclick = ( ) => { printTab ( 2 ) ; } ;
1759+ searchState . focusedByTab = [ ] ;
1760+ let i = 0 ;
1761+ for ( const elem of elems ) {
1762+ const j = i ;
1763+ elem . onclick = ( ) => { printTab ( j ) ; } ;
1764+ searchState . focusedByTab . push ( null ) ;
1765+ i += 1 ;
1766+ }
17551767 printTab ( currentTab ) ;
17561768 }
17571769
0 commit comments