diff --git a/apps/client/src/widgets/sidebar/TableOfContents.tsx b/apps/client/src/widgets/sidebar/TableOfContents.tsx
index 696e37e56..b84a138bf 100644
--- a/apps/client/src/widgets/sidebar/TableOfContents.tsx
+++ b/apps/client/src/widgets/sidebar/TableOfContents.tsx
@@ -2,7 +2,7 @@ import "./TableOfContents.css";
import { CKTextEditor, ModelElement } from "@triliumnext/ckeditor5";
import clsx from "clsx";
-import { useEffect, useState } from "preact/hooks";
+import { useCallback, useEffect, useState } from "preact/hooks";
import { t } from "../../services/i18n";
import { useActiveNoteContext, useContentElement, useIsNoteReadOnly, useNoteProperty, useTextEditor } from "../react/hooks";
@@ -33,20 +33,25 @@ export default function TableOfContents() {
);
}
-function AbstractTableOfContents({ headings }: {
+function AbstractTableOfContents({ headings, scrollToHeading }: {
headings: RawHeading[];
+ scrollToHeading(heading: RawHeading): void;
}) {
const nestedHeadings = buildHeadingTree(headings);
return (
- {nestedHeadings.map(heading =>
);
}
-function TableOfContentsHeading({ heading }: { heading: HeadingsWithNesting }) {
+function TableOfContentsHeading({ heading, scrollToHeading }: {
+ heading: HeadingsWithNesting;
+ scrollToHeading(heading: RawHeading): void;
+}) {
+ console.log("Got ", scrollToHeading);
const [ collapsed, setCollapsed ] = useState(false);
return (
<>
@@ -58,11 +63,14 @@ function TableOfContentsHeading({ heading }: { heading: HeadingsWithNesting }) {
onClick={() => setCollapsed(!collapsed)}
/>
)}
- {heading.text}
+ scrollToHeading(heading)}
+ >{heading.text}
{heading.children && (