Skip to content

Commit 15fe31f

Browse files
committed
Stop the TOC jittering sideways as the highlight moves
Active TOC links step from weight 430 to 470, and the rail is a fit-content column — every active-section change re-measured the longest link and shifted the rail a pixel or two side to side. Each link now carries a hidden zero-height ghost of itself at the active weight, so the column always occupies its bold width and the highlight moves without the layout moving.
1 parent 02b32cf commit 15fe31f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎apps/sim/lib/workspace-files/artifact-stylesheet.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ figcaption { font-size: 0.875em; line-height: 1.4285714; color: var(--text-prima
517517
}
518518
.toc-items a:first-of-type { padding-top: 0; }
519519
.toc-items a:last-of-type { padding-bottom: 0; }
520+
/* Hidden ghost at the ACTIVE weight: each link always occupies its bold
521+
width, so the weight flip on highlight cannot jitter the fit-content
522+
column side to side while scrolling. */
523+
.toc-items a::after {
524+
content: attr(data-text);
525+
display: block; height: 0; visibility: hidden; overflow: hidden;
526+
font-weight: 470; pointer-events: none;
527+
}
520528
.toc-items a[data-depth="2"] { padding-left: 20px; }
521529
.toc-items a[data-depth="3"] { padding-left: 32px; }
522530
.toc-items a:hover { color: var(--text-body); }
@@ -658,6 +666,9 @@ export const SIM_ARTIFACT_SHELL = `<script>
658666
a.href = '#' + h.id
659667
a.textContent = h.textContent
660668
a.dataset.depth = h.tagName === 'H2' ? '2' : '3'
669+
// Reserves the active (bolder) width so the fit-content column never
670+
// resizes as the highlight moves — see the ::after ghost in the sheet.
671+
a.dataset.text = h.textContent || ''
661672
tocItems.appendChild(a)
662673
tocLinks.push(a)
663674
}

0 commit comments

Comments
 (0)