]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/html/static/js/scrape-examples.js
Rollup merge of #105359 - flba-eb:thread_local_key_sentinel_value, r=m-ou-se
[rust.git] / src / librustdoc / html / static / js / scrape-examples.js
index 830b44d6bc0fd16fcc2ca108af802c883c6fe55e..7a3a9c5f3400190fb62ec8ea3ee904171a06d048 100644 (file)
@@ -6,6 +6,8 @@
     // Number of lines shown when code viewer is not expanded.
     // DEFAULT is the first example shown by default, while HIDDEN is
     // the examples hidden beneath the "More examples" toggle.
+    //
+    // NOTE: these values MUST be synchronized with certain rules in rustdoc.css!
     const DEFAULT_MAX_LINES = 5;
     const HIDDEN_MAX_LINES = 10;
 
         } else {
             const wrapper = elt.querySelector(".code-wrapper");
             const halfHeight = wrapper.offsetHeight / 2;
-            const offsetMid = (lines.children[loc[0]].offsetTop
-                             + lines.children[loc[1]].offsetTop) / 2;
+            const offsetTop = lines.children[loc[0]].offsetTop;
+            const lastLine = lines.children[loc[1]];
+            const offsetBot = lastLine.offsetTop + lastLine.offsetHeight;
+            const offsetMid = (offsetTop + offsetBot) / 2;
             scrollOffset = offsetMid - halfHeight;
         }