about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2023-12-15 12:26:09 +0100
committerGuillaume Gomez <guillaume.gomez@huawei.com>2023-12-15 12:26:09 +0100
commit552143c875d4bd037ae9bbd73440dfc77c6e6dee (patch)
treed57f0450fdd7b45dc4a22924123a9a59e8f555fe
parentfc7221689e6dcb32dbf72befa465d851d92263d8 (diff)
downloadrust-552143c875d4bd037ae9bbd73440dfc77c6e6dee.tar.gz
rust-552143c875d4bd037ae9bbd73440dfc77c6e6dee.zip
Simplify `src-script.js` code
-rw-r--r--src/librustdoc/html/static/js/src-script.js15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js
index 27b5cf1e2ae..8b7a9161d71 100644
--- a/src/librustdoc/html/static/js/src-script.js
+++ b/src/librustdoc/html/static/js/src-script.js
@@ -131,12 +131,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;
     }
@@ -218,12 +214,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);