Skip to content

Commit 3a6bef0

Browse files
committed
Auto merge of rust-lang#61008 - GuillaumeGomez:fix-rustdoc-code-highlighting, r=Manishearth
Fix lines highlighting in rustdoc source view Fixes rust-lang#60948. This PR fixes how we handle the lines highlighting from the URL (so in "/doc/src/alloc/string.rs.html#285-283", the "285-283" part). We got a hard limit on 50000, for some unknown and lost reasons which was used in case only one line is selected. r? @Manishearth
2 parents 607aadc + 8ca3887 commit 3a6bef0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/librustdoc/html/static/main.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ if (!DOMTokenList.prototype.remove) {
162162
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
163163
if (match) {
164164
from = parseInt(match[1], 10);
165-
to = Math.min(50000, parseInt(match[2] || match[1], 10));
166-
from = Math.min(from, to);
165+
to = from;
166+
if (typeof match[2] !== "undefined") {
167+
to = parseInt(match[2], 10);
168+
}
169+
if (to < from) {
170+
var tmp = to;
171+
to = from;
172+
from = tmp;
173+
}
167174
elem = document.getElementById(from);
168175
if (!elem) {
169176
return;
@@ -180,7 +187,11 @@ if (!DOMTokenList.prototype.remove) {
180187
});
181188
});
182189
for (i = from; i <= to; ++i) {
183-
addClass(document.getElementById(i), "line-highlighted");
190+
elem = document.getElementById(i);
191+
if (!elem) {
192+
break;
193+
}
194+
addClass(elem, "line-highlighted");
184195
}
185196
} else if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
186197
addClass(search, "hidden");

0 commit comments

Comments
 (0)