File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
src/librustdoc/html/static Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -1931,18 +1931,24 @@ in storage.js
19311931}
19321932
19331933.scraped-example : not (.expanded ) .code-wrapper {
1934- max-height : 120px ;
1934+ /* scrape-examples.js has a constant DEFAULT_MAX_LINES (call it N) for the number
1935+ * of lines shown in the un-expanded example code viewer. This pre needs to have
1936+ * a max-height equal to line-height * N. The line-height is currently 1.5em,
1937+ * and we include additional 10px for padding. */
1938+ max-height : calc (1.5em * 5 + 10px );
19351939}
19361940
19371941.scraped-example : not (.expanded ) .code-wrapper pre {
19381942 overflow-y : hidden;
1939- max-height : 120px ;
19401943 padding-bottom : 0 ;
1944+ /* See above comment, should be the same max-height. */
1945+ max-height : calc (1.5em * 5 + 10px );
19411946}
19421947
19431948.more-scraped-examples .scraped-example : not (.expanded ) .code-wrapper ,
19441949.more-scraped-examples .scraped-example : not (.expanded ) .code-wrapper pre {
1945- max-height : 240px ;
1950+ /* See above comment, except this height is based on HIDDEN_MAX_LINES. */
1951+ max-height : calc (1.5em * 10 + 10px );
19461952}
19471953
19481954.scraped-example .code-wrapper .next ,
Original file line number Diff line number Diff line change 66 // Number of lines shown when code viewer is not expanded.
77 // DEFAULT is the first example shown by default, while HIDDEN is
88 // the examples hidden beneath the "More examples" toggle.
9+ //
10+ // NOTE: these values MUST be synchronized with certain rules in rustdoc.css!
911 const DEFAULT_MAX_LINES = 5 ;
1012 const HIDDEN_MAX_LINES = 10 ;
1113
2426 } else {
2527 const wrapper = elt . querySelector ( ".code-wrapper" ) ;
2628 const halfHeight = wrapper . offsetHeight / 2 ;
27- const offsetMid = ( lines . children [ loc [ 0 ] ] . offsetTop
28- + lines . children [ loc [ 1 ] ] . offsetTop ) / 2 ;
29+ const offsetTop = lines . children [ loc [ 0 ] ] . offsetTop ;
30+ const lastLine = lines . children [ loc [ 1 ] ] ;
31+ const offsetBot = lastLine . offsetTop + lastLine . offsetHeight ;
32+ const offsetMid = ( offsetTop + offsetBot ) / 2 ;
2933 scrollOffset = offsetMid - halfHeight ;
3034 }
3135
You can’t perform that action at this time.
0 commit comments