]> git.lizzy.rs Git - rust.git/commitdiff
Fix navbar click while in a search
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 6 Nov 2017 20:14:37 +0000 (21:14 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 6 Nov 2017 22:49:47 +0000 (23:49 +0100)
src/librustdoc/html/static/main.js

index b1120e0af38949e13daa2d1eb2125e2098291766..2abc8f7eb6ad0baeb30a89e0cdb7eb0c89eb1301 100644 (file)
     }
 
     function highlightSourceLines(ev) {
+        var search = document.getElementById("search");
         var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
         if (match) {
             from = parseInt(match[1], 10);
             for (i = from; i <= to; ++i) {
                 addClass(document.getElementById(i), 'line-highlighted');
             }
+        } else if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
+            addClass(search, "hidden");
+            removeClass(document.getElementById("main"), "hidden");
+            var hash = ev.newURL.slice(ev.newURL.indexOf('#') + 1);
+            var elem = document.getElementById(hash);
+            if (elem) {
+                elem.scrollIntoView();
+            }
         }
     }
     highlightSourceLines(null);