From 382d5bb715859423a086c6b26e651c18adf0dcb9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Jul 2020 15:45:01 +0200 Subject: [PATCH 1/2] Focus on the current file in the source file sidebar --- src/librustdoc/html/static/source-script.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/librustdoc/html/static/source-script.js b/src/librustdoc/html/static/source-script.js index cfbfe6675f52b..5c39e760f44d4 100644 --- a/src/librustdoc/html/static/source-script.js +++ b/src/librustdoc/html/static/source-script.js @@ -140,4 +140,9 @@ function createSourceSidebar() { }); main.insertBefore(sidebar, main.firstChild); + // Focus on the current file in the source files sidebar. + var selected_elems = Array.prototype.slice.call(sidebar.getElementsByClassName("selected")); + if (selected_elems.length > 0) { + selected_elems[0].focus(); + } } From 52c65e05f53e7a49345bc3041e5656735fdc4f9c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 16 Jul 2020 18:34:49 +0200 Subject: [PATCH 2/2] Remove elements iterator clone and only keep first element instead --- src/librustdoc/html/static/source-script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/source-script.js b/src/librustdoc/html/static/source-script.js index 5c39e760f44d4..6805f2a266f09 100644 --- a/src/librustdoc/html/static/source-script.js +++ b/src/librustdoc/html/static/source-script.js @@ -141,8 +141,8 @@ function createSourceSidebar() { main.insertBefore(sidebar, main.firstChild); // Focus on the current file in the source files sidebar. - var selected_elems = Array.prototype.slice.call(sidebar.getElementsByClassName("selected")); - if (selected_elems.length > 0) { - selected_elems[0].focus(); + var selected_elem = sidebar.getElementsByClassName("selected")[0]; + if (typeof selected_elem !== "undefined") { + selected_elem.focus(); } }