Skip to content

Commit cb2ba3b

Browse files
Better line hight computation.
1 parent 593a4dc commit cb2ba3b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

public/application.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)