@@ -43,26 +43,33 @@ const TY_KEYWORD = itemTypes.indexOf("keyword");
43
43
44
44
// In the search display, allows to switch between tabs.
45
45
function 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 ;
50
49
onEachLazy ( document . getElementById ( "titles" ) . childNodes , elem => {
51
- if ( nb_copy === 0 ) {
50
+ if ( nb === iter ) {
52
51
addClass ( elem , "selected" ) ;
52
+ foundCurrentTab = true ;
53
53
} else {
54
54
removeClass ( elem , "selected" ) ;
55
55
}
56
- nb_copy - = 1 ;
56
+ iter + = 1 ;
57
57
} ) ;
58
+ iter = 0 ;
58
59
onEachLazy ( document . getElementById ( "results" ) . childNodes , elem => {
59
- if ( nb === 0 ) {
60
+ if ( nb === iter ) {
60
61
addClass ( elem , "active" ) ;
62
+ foundCurrentResultSet = true ;
61
63
} else {
62
64
removeClass ( elem , "active" ) ;
63
65
}
64
- nb - = 1 ;
66
+ iter + = 1 ;
65
67
} ) ;
68
+ if ( foundCurrentTab && foundCurrentResultSet ) {
69
+ searchState . currentTab = nb ;
70
+ } else if ( nb != 0 ) {
71
+ printTab ( 0 ) ;
72
+ }
66
73
}
67
74
68
75
/**
@@ -1731,6 +1738,7 @@ window.initSearch = rawSearchIndex => {
1731
1738
output += '<div id="titles">' +
1732
1739
makeTabHeader ( 0 , signatureTabTitle , ret_others [ 1 ] ) +
1733
1740
"</div>" ;
1741
+ currentTab = 0 ;
1734
1742
}
1735
1743
1736
1744
const resultsElem = document . createElement ( "div" ) ;
@@ -1746,12 +1754,16 @@ window.initSearch = rawSearchIndex => {
1746
1754
}
1747
1755
search . appendChild ( resultsElem ) ;
1748
1756
// Reset focused elements.
1749
- searchState . focusedByTab = [ null , null , null ] ;
1750
1757
searchState . showResults ( search ) ;
1751
1758
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
+ }
1755
1767
printTab ( currentTab ) ;
1756
1768
}
1757
1769
0 commit comments