Skip to content

Commit

Permalink
Rollup merge of rust-lang#118977 - GuillaumeGomez:simplifysrc-script,…
Browse files Browse the repository at this point in the history
… r=notriddle

Simplify `src-script.js` code

Instead of keeping this value in the global scope and still use it in the function in case it wasn't used outside, let's just use it inside the function.

r? `@notriddle`
  • Loading branch information
matthiaskrgr authored Dec 15, 2023
2 parents f80d5c3 + 552143c commit 7b08d99
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/librustdoc/html/static/js/src-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ function createSrcSidebar() {
}
}

const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;

function highlightSrcLines(match) {
if (typeof match === "undefined") {
match = window.location.hash.match(lineNumbersRegex);
}
function highlightSrcLines() {
const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
if (!match) {
return;
}
Expand Down Expand Up @@ -233,12 +229,7 @@ const handleSrcHighlight = (function() {
};
}());

window.addEventListener("hashchange", () => {
const match = window.location.hash.match(lineNumbersRegex);
if (match) {
return highlightSrcLines(match);
}
});
window.addEventListener("hashchange", highlightSrcLines);

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

0 comments on commit 7b08d99

Please sign in to comment.