@@ -161,17 +161,18 @@ function getSearchElement() {
161
161
return window . history && typeof window . history . pushState === "function" ;
162
162
}
163
163
164
+ function isHidden ( elem ) {
165
+ return elem . offsetHeight === 0 ;
166
+ }
167
+
164
168
var main = document . getElementById ( "main" ) ;
169
+ var savedHash = "" ;
165
170
166
- function onHashChange ( ev ) {
167
- // If we're in mobile mode, we should hide the sidebar in any case.
168
- hideSidebar ( ) ;
169
- var match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
170
- if ( match ) {
171
- return highlightSourceLines ( match , ev ) ;
172
- }
171
+ function handleHashes ( ev ) {
173
172
var search = getSearchElement ( ) ;
174
173
if ( ev !== null && search && ! hasClass ( search , "hidden" ) && ev . newURL ) {
174
+ // This block occurs when clicking on an element in the navbar while
175
+ // in a search.
175
176
addClass ( search , "hidden" ) ;
176
177
removeClass ( main , "hidden" ) ;
177
178
var hash = ev . newURL . slice ( ev . newURL . indexOf ( "#" ) + 1 ) ;
@@ -183,6 +184,35 @@ function getSearchElement() {
183
184
elem . scrollIntoView ( ) ;
184
185
}
185
186
}
187
+ // This part is used in case an element is not visible.
188
+ if ( savedHash !== window . location . hash ) {
189
+ savedHash = window . location . hash ;
190
+ if ( savedHash . length === 0 ) {
191
+ return ;
192
+ }
193
+ var elem = document . getElementById ( savedHash . slice ( 1 ) ) ; // we remove the '#'
194
+ if ( ! elem || ! isHidden ( elem ) ) {
195
+ return ;
196
+ }
197
+ var parent = elem . parentNode ;
198
+ if ( parent && hasClass ( parent , "impl-items" ) ) {
199
+ // In case this is a trait implementation item, we first need to toggle
200
+ // the "Show hidden undocumented items".
201
+ onEachLazy ( parent . getElementsByClassName ( "collapsed" ) , function ( e ) {
202
+ if ( e . parentNode === parent ) {
203
+ // Only click on the toggle we're looking for.
204
+ e . click ( ) ;
205
+ return true ;
206
+ }
207
+ } ) ;
208
+ if ( isHidden ( elem ) ) {
209
+ // The whole parent is collapsed. We need to click on its toggle as well!
210
+ if ( hasClass ( parent . lastElementChild , "collapse-toggle" ) ) {
211
+ parent . lastElementChild . click ( ) ;
212
+ }
213
+ }
214
+ }
215
+ }
186
216
}
187
217
188
218
function highlightSourceLines ( match , ev ) {
@@ -228,6 +258,16 @@ function getSearchElement() {
228
258
}
229
259
}
230
260
261
+ function onHashChange ( ev ) {
262
+ // If we're in mobile mode, we should hide the sidebar in any case.
263
+ hideSidebar ( ) ;
264
+ var match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
265
+ if ( match ) {
266
+ return highlightSourceLines ( match , ev ) ;
267
+ }
268
+ handleHashes ( ) ;
269
+ }
270
+
231
271
function expandSection ( id ) {
232
272
var elem = document . getElementById ( id ) ;
233
273
if ( elem && isHidden ( elem ) ) {
@@ -246,9 +286,6 @@ function getSearchElement() {
246
286
}
247
287
}
248
288
249
- highlightSourceLines ( ) ;
250
- window . onhashchange = onHashChange ;
251
-
252
289
// Gets the human-readable string for the virtual-key code of the
253
290
// given KeyboardEvent, ev.
254
291
//
@@ -2615,6 +2652,10 @@ function getSearchElement() {
2615
2652
insertAfter ( popup , getSearchElement ( ) ) ;
2616
2653
}
2617
2654
2655
+ handleHashes ( ) ;
2656
+ highlightSourceLines ( ) ;
2657
+ window . onhashchange = onHashChange ;
2658
+
2618
2659
buildHelperPopup ( ) ;
2619
2660
} ( ) ) ;
2620
2661
0 commit comments