Skip to content

Commit acd5e8c

Browse files
Fix navbar click while in a search
1 parent 58557fa commit acd5e8c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/librustdoc/html/static/main.js

+9
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
}
123123

124124
function highlightSourceLines(ev) {
125+
var search = document.getElementById("search");
125126
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
126127
if (match) {
127128
from = parseInt(match[1], 10);
@@ -145,6 +146,14 @@
145146
for (i = from; i <= to; ++i) {
146147
addClass(document.getElementById(i), 'line-highlighted');
147148
}
149+
} else if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
150+
addClass(search, "hidden");
151+
removeClass(document.getElementById("main"), "hidden");
152+
var hash = ev.newURL.slice(ev.newURL.indexOf('#') + 1);
153+
var elem = document.getElementById(hash);
154+
if (elem) {
155+
elem.scrollIntoView();
156+
}
148157
}
149158
}
150159
highlightSourceLines(null);

0 commit comments

Comments
 (0)