Skip to content

Commit 3f4b417

Browse files
Fix scrolling to anchor offset
1 parent 9c23e86 commit 3f4b417

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

packages/cursorless-org-docs/src/docs/user/languages/components/DynamicTOC.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,29 @@ export default function DynamicTOC() {
1616
}
1717

1818
function getTOC() {
19-
const headingElements = Array.from(document.querySelectorAll("h3")).map(
20-
(el) => ({
21-
id: el.id,
22-
text: el.textContent?.replace("#", "") ?? "",
23-
}),
24-
);
25-
2619
const col = document.createElement("div");
2720
col.className = "col col--3";
2821

2922
const toc = document.createElement("div");
3023
toc.className = "tableOfContents_tkZC thin-scrollbar";
31-
toc.style.position = "fixed";
32-
toc.style.right = "1rem";
33-
toc.style.width = "14rem";
34-
col.appendChild(toc);
3524

3625
const ul = document.createElement("ul");
3726
ul.className = "table-of-contents table-of-contents__left-border";
38-
toc.appendChild(ul);
3927

40-
headingElements.forEach((h) => {
28+
document.querySelectorAll("h3").forEach((header) => {
4129
const li = document.createElement("li");
4230

4331
const a = document.createElement("a");
44-
a.href = `#${h.id}`;
32+
a.href = `#${header.id}`;
4533
a.className = "table-of-contents__link";
46-
a.textContent = h.text;
34+
a.textContent = header.textContent;
4735

4836
li.appendChild(a);
4937
ul.appendChild(li);
5038
});
5139

40+
toc.appendChild(ul);
41+
col.appendChild(toc);
42+
5243
return col;
5344
}

packages/cursorless-org-docs/src/docs/user/languages/components/Language.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function Language({ languageId }: Props) {
1010
return (
1111
<>
1212
<DynamicTOC />
13+
1314
<ScopeSupport languageId={languageId} />
1415
</>
1516
);
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
.facet-name {
22
font-weight: 600;
33
}
4-
5-
.scope-header a {
6-
display: none;
7-
margin-left: 0.5rem;
8-
}
9-
10-
.scope-header:hover a {
11-
display: inline;
12-
}

packages/cursorless-org-docs/src/docs/user/languages/components/ScopeSupport.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ function renderScope(
8888
const href = scope.scope.toLowerCase().replaceAll(" ", "-");
8989
return (
9090
<div key={scope.scope}>
91-
<h3 id={href} className="scope-header">
91+
<h3 id={href} className="scope-header anchorWithStickyNavbar_IncK">
9292
{scope.scope}
93-
<a href={`#${href}`}>#</a>
93+
<a className="hash-link" href={`#${href}`} />
9494
</h3>
9595
{scope.facets.map((f) =>
9696
renderFacet(languageId, rangeType, renderWhitespace, f),

0 commit comments

Comments
 (0)