Skip to content

Commit c527502

Browse files
Scroll when the anchor change and is linking outside of the displayed content
1 parent c42d846 commit c527502

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/librustdoc/html/static/js/source-script.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function createSourceSidebar() {
149149

150150
var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
151151

152-
function highlightSourceLines(scrollTo, match) {
152+
function highlightSourceLines(match) {
153153
if (typeof match === "undefined") {
154154
match = window.location.hash.match(lineNumbersRegex);
155155
}
@@ -170,11 +170,9 @@ function highlightSourceLines(scrollTo, match) {
170170
if (!elem) {
171171
return;
172172
}
173-
if (scrollTo) {
174-
var x = document.getElementById(from);
175-
if (x) {
176-
x.scrollIntoView();
177-
}
173+
var x = document.getElementById(from);
174+
if (x) {
175+
x.scrollIntoView();
178176
}
179177
onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
180178
onEachLazy(e.getElementsByTagName("span"), function(i_e) {
@@ -198,7 +196,7 @@ var handleSourceHighlight = (function() {
198196
y = window.scrollY;
199197
if (searchState.browserSupportsHistoryApi()) {
200198
history.replaceState(null, null, "#" + name);
201-
highlightSourceLines(true);
199+
highlightSourceLines();
202200
} else {
203201
location.replace("#" + name);
204202
}
@@ -230,15 +228,15 @@ var handleSourceHighlight = (function() {
230228
window.addEventListener("hashchange", function() {
231229
var match = window.location.hash.match(lineNumbersRegex);
232230
if (match) {
233-
return highlightSourceLines(false, match);
231+
return highlightSourceLines(match);
234232
}
235233
});
236234

237235
onEachLazy(document.getElementsByClassName("line-numbers"), function(el) {
238236
el.addEventListener("click", handleSourceHighlight);
239237
});
240238

241-
highlightSourceLines(true);
239+
highlightSourceLines();
242240

243241
window.createSourceSidebar = createSourceSidebar;
244242
})();

0 commit comments

Comments
 (0)