File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,9 +31,15 @@ function applyCodeFocus() {
3131 const pre = scroll . querySelector ( 'pre' ) ;
3232 if ( ! pre ) return ;
3333
34- const code = pre . querySelector ( 'code, syntax-code' ) || pre ;
35- const style = getComputedStyle ( code ) ;
36- const lineHeight = parseFloat ( style . lineHeight ) || parseFloat ( style . fontSize ) * 1.6 ;
34+ // Measure actual line height by rendering a single line and measuring it:
35+ const probe = document . createElement ( 'span' ) ;
36+ probe . textContent = 'X' ;
37+ probe . style . visibility = 'hidden' ;
38+ probe . style . position = 'absolute' ;
39+ pre . appendChild ( probe ) ;
40+ const singleHeight = probe . getBoundingClientRect ( ) . height ;
41+ pre . removeChild ( probe ) ;
42+ const lineHeight = singleHeight ;
3743
3844 const padding = parseFloat ( getComputedStyle ( scroll ) . paddingTop ) || 16 ;
3945 const viewportHeight = viewport . clientHeight ;
You can’t perform that action at this time.
0 commit comments