Skip to content

Commit 552143c

Browse files
Simplify src-script.js code
1 parent fc72216 commit 552143c

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

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

+3-12
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,8 @@ function createSrcSidebar() {
131131
}
132132
}
133133

134-
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
135-
136-
function highlightSrcLines(match) {
137-
if (typeof match === "undefined") {
138-
match = window.location.hash.match(lineNumbersRegex);
139-
}
134+
function highlightSrcLines() {
135+
const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
140136
if (!match) {
141137
return;
142138
}
@@ -218,12 +214,7 @@ const handleSrcHighlight = (function() {
218214
};
219215
}());
220216

221-
window.addEventListener("hashchange", () => {
222-
const match = window.location.hash.match(lineNumbersRegex);
223-
if (match) {
224-
return highlightSrcLines(match);
225-
}
226-
});
217+
window.addEventListener("hashchange", highlightSrcLines);
227218

228219
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
229220
el.addEventListener("click", handleSrcHighlight);

0 commit comments

Comments
 (0)