Skip to content

Build your personal knowledge base with Trilium Notes

chore(toc): drop the active-heading option

Elian Doranaa0a94cb6e0b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 366b9ff97a..b6fb1df575 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1490,9 +1490,7 @@
"description": "Table of contents will appear in text notes when the note has more than a defined number of headings. You can customize this number:",
"unit": "headings",
"disable_info": "You can also use this option to effectively disable TOC by setting a very high number.",
- "shortcut_info": "You can configure a keyboard shortcut for quickly toggling the right pane (including TOC) in the Options -> Shortcuts (name 'toggleRightPane').",
- "active_heading_enabled": "Show active heading",
- "active_heading_description": "While reading a note, sync the table of contents with the currently viewed heading."
+ "shortcut_info": "You can configure a keyboard shortcut for quickly toggling the right pane (including TOC) in the Options -> Shortcuts (name 'toggleRightPane')."
},
"text_auto_read_only_size": {
"title": "Automatic Read-Only Size",
@@ -1957,9 +1955,7 @@
"toc": {
"table_of_contents": "Table of Contents",
"options": "Options",
- "no_headings": "No headings.",
- "modal_title": "Configure Table of Contents",
- "menu_configure": "Configure table of contents..."
+ "no_headings": "No headings."
},
"watched_file_update_status": {
"file_last_modified": "File <code class=\"file-path\"></code> has been last modified on <span class=\"file-last-modified\"></span>.",
diff --git a/apps/client/src/widgets/sidebar/TableOfContents.tsx b/apps/client/src/widgets/sidebar/TableOfContents.tsx
index 43da4da5d2..089e549b36 100644
--- a/apps/client/src/widgets/sidebar/TableOfContents.tsx
+++ b/apps/client/src/widgets/sidebar/TableOfContents.tsx
@@ -1,17 +1,14 @@
import "./TableOfContents.css";
import { attributeChangeAffectsHeading, CKTextEditor, ModelElement, type ModelNode } from "@triliumnext/ckeditor5";
-import { createPortal } from "preact/compat";
import clsx from "clsx";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import { t } from "../../services/i18n";
import { randomString } from "../../services/utils";
-import { useActiveNoteContext, useContentElement, useGetContextData, useIsNoteReadOnly, useMathRendering, useNoteProperty, useTextEditor, useTriliumOptionBool } from "../react/hooks";
+import { useActiveNoteContext, useContentElement, useGetContextData, useIsNoteReadOnly, useMathRendering, useNoteProperty, useTextEditor } from "../react/hooks";
import Icon from "../react/Icon";
-import Modal from "../react/Modal";
import RawHtml from "../react/RawHtml";
-import { TableOfContentOptions } from "../type_widgets/options/text_notes";
import RightPanelWidget from "./RightPanelWidget";
//#region Generic impl.
@@ -31,60 +28,30 @@ export interface HeadingContext {
activeHeadingId?: string | null;
}
-function TableOfContentOptionsModal({ shown, setShown }: { shown: boolean, setShown(value: boolean): void }) {
- return (
- <Modal
- className="toc-options-modal"
- size="md"
- title={t("toc.modal_title")}
- show={shown}
- onHidden={() => setShown(false)}
- >
- <TableOfContentOptions />
- </Modal>
- );
-}
-
export default function TableOfContents() {
const { note, noteContext } = useActiveNoteContext();
const noteType = useNoteProperty(note, "type");
const noteMime = useNoteProperty(note, "mime");
const { isReadOnly } = useIsNoteReadOnly(note, noteContext);
- const [shown, setShown] = useState(false);
return (
- <>
- <RightPanelWidget
- id="toc"
- title={t("toc.table_of_contents")}
- contextMenuItems={[
- {
- title: t("toc.menu_configure"),
- uiIcon: "bx bx-cog",
- handler: () => setShown(true)
- }
- ]}
- grow
- >
- {((noteType === "text" && isReadOnly) || (noteType === "doc")) && <ReadOnlyTextTableOfContents />}
- {noteType === "text" && !isReadOnly && <EditableTextTableOfContents />}
- {noteType === "file" && noteMime === "application/pdf" && <ContextDataTableOfContents />}
- {note?.isMarkdown() && <ContextDataTableOfContents />}
- </RightPanelWidget>
- {createPortal(<TableOfContentOptionsModal shown={shown} setShown={setShown} />, document.body)}
- </>
+ <RightPanelWidget id="toc" title={t("toc.table_of_contents")} grow>
+ {((noteType === "text" && isReadOnly) || (noteType === "doc")) && <ReadOnlyTextTableOfContents />}
+ {noteType === "text" && !isReadOnly && <EditableTextTableOfContents />}
+ {noteType === "file" && noteMime === "application/pdf" && <ContextDataTableOfContents />}
+ {note?.isMarkdown() && <ContextDataTableOfContents />}
+ </RightPanelWidget>
);
}
function ContextDataTableOfContents() {
const data = useGetContextData("toc");
- const [tocActiveHeadingEnabled] = useTriliumOptionBool("tocActiveHeadingEnabled");
return (
<AbstractTableOfContents
headings={data?.headings || []}
scrollToHeading={data?.scrollToHeading || (() => {})}
- activeHeadingId={tocActiveHeadingEnabled ? data?.activeHeadingId : null}
+ activeHeadingId={data?.activeHeadingId}
/>
);
}
@@ -246,7 +213,6 @@ function EditableTextTableOfContents() {
const textEditor = useTextEditor(noteContext);
const [ headings, setHeadings ] = useState<CKHeading[]>([]);
const [ scrollingContainer, setScrollingContainer ] = useState<HTMLElement | null>(null);
- const [ tocActiveHeadingEnabled ] = useTriliumOptionBool("tocActiveHeadingEnabled");
useEffect(() => {
if (!textEditor) return;
@@ -275,24 +241,24 @@ function EditableTextTableOfContents() {
}, [ textEditor, note ]);
useEffect(() => {
- if (!tocActiveHeadingEnabled || !textEditor) {
+ if (!textEditor) {
setScrollingContainer(null);
return;
}
const container = textEditor.editing.view.getDomRoot()?.closest(".scrolling-container") as HTMLElement | null;
setScrollingContainer(container);
- }, [tocActiveHeadingEnabled, textEditor]);
+ }, [textEditor]);
const getHeadingElement = useCallback((heading: CKHeading) => {
- if (!tocActiveHeadingEnabled || !textEditor) return null;
+ if (!textEditor) return null;
- const viewEl = textEditor?.editing.mapper.toViewElement(heading.element);
+ const viewEl = textEditor.editing.mapper.toViewElement(heading.element);
if (!viewEl) return null;
const domEl = textEditor.editing.view.domConverter.mapViewToDom(viewEl);
return domEl ?? null;
- }, [tocActiveHeadingEnabled, textEditor]);
+ }, [textEditor]);
const activeHeadingId = useActiveHeading({ headings, scrollingContainer, getHeadingElement });
@@ -387,7 +353,6 @@ function ReadOnlyTextTableOfContents() {
const { noteContext } = useActiveNoteContext();
const contentEl = useContentElement(noteContext);
const [ headings, setHeadings ] = useState<DomHeading[]>([]);
- const [tocActiveHeadingEnabled] = useTriliumOptionBool("tocActiveHeadingEnabled");
const [ scrollingContainer, setScrollingContainer ] = useState<HTMLElement | null>(null);
useEffect(() => {
@@ -408,14 +373,14 @@ function ReadOnlyTextTableOfContents() {
}, []);
useEffect(() => {
- if (!tocActiveHeadingEnabled || !contentEl) {
+ if (!contentEl) {
setScrollingContainer(null);
return;
}
const container = contentEl.closest(".scrolling-container") as HTMLElement;
setScrollingContainer(container);
- }, [tocActiveHeadingEnabled, contentEl]);
+ }, [contentEl]);
const getHeadingElement = useCallback((heading: DomHeading) => heading.element, []);
@@ -444,4 +409,4 @@ function extractTocFromStaticHtml(el: HTMLElement | null) {
return headings;
}
-//#endregion
\ No newline at end of file
+//#endregion
diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
index 2429390c5b..f5660db3e2 100644
--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx
+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
@@ -407,28 +407,21 @@ interface ThemeData {
function TableOfContent() {
const [ minTocHeadings, setMinTocHeadings ] = useTriliumOption("minTocHeadings");
- return (
+ return (!isNewLayout &&
<OptionsSection title={t("table_of_contents.title")}>
- {isNewLayout && (
- <TableOfContentOptions />
- )}
- {!isNewLayout && (
- <>
- <FormText>{t("table_of_contents.description")}</FormText>
-
- <FormGroup name="min-toc-headings">
- <FormTextBoxWithUnit
- type="number"
- min={0} max={999999999999999} step={1}
- unit={t("table_of_contents.unit")}
- currentValue={minTocHeadings} onChange={setMinTocHeadings}
- />
- </FormGroup>
+ <FormText>{t("table_of_contents.description")}</FormText>
- <FormText>{t("table_of_contents.disable_info")}</FormText>
- <FormText>{t("table_of_contents.shortcut_info")}</FormText>
- </>
- )}
+ <FormGroup name="min-toc-headings">
+ <FormTextBoxWithUnit
+ type="number"
+ min={0} max={999999999999999} step={1}
+ unit={t("table_of_contents.unit")}
+ currentValue={minTocHeadings} onChange={setMinTocHeadings}
+ />
+ </FormGroup>
+
+ <FormText>{t("table_of_contents.disable_info")}</FormText>
+ <FormText>{t("table_of_contents.shortcut_info")}</FormText>
</OptionsSection>
);
}
@@ -450,22 +443,6 @@ function HighlightsList() {
);
}
-export function TableOfContentOptions() {
- const [ tocActiveHeadingEnabled, setTocActiveHeadingEnabled ] = useTriliumOptionBool("tocActiveHeadingEnabled");
-
- return (
- <>
- <OptionsRowWithToggle
- name="active-heading-enabled"
- label={t("table_of_contents.active_heading_enabled")}
- description={t("table_of_contents.active_heading_description")}
- currentValue={tocActiveHeadingEnabled}
- onChange={setTocActiveHeadingEnabled}
- />
- </>
- );
-}
-
export function HighlightsListOptions() {
const [ highlightsList, setHighlightsList ] = useTriliumOptionJson<string[]>("highlightsList");
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index fedd865ff3..94c5db6841 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -125,7 +125,6 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
maxContentWidth: number;
centerContent: boolean;
minTocHeadings: number;
- tocActiveHeadingEnabled: boolean;
eraseUnusedAttachmentsAfterSeconds: number;
eraseUnusedAttachmentsAfterTimeScale: number;
logRetentionDays: number;
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index 03d55c8338..c7eba5aa04 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -86,7 +86,6 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"compressImages",
"downloadImagesAutomatically",
"minTocHeadings",
- "tocActiveHeadingEnabled",
"highlightsList",
"checkForUpdates",
"disableTray",
diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts
index bdb11e7e6e..c5b09aba5e 100644
--- a/packages/trilium-core/src/services/options_init.ts
+++ b/packages/trilium-core/src/services/options_init.ts
@@ -162,7 +162,6 @@ const defaultOptions: DefaultOption[] = [
{ name: "compressImages", value: "true", isSynced: true },
{ name: "downloadImagesAutomatically", value: "true", isSynced: true },
{ name: "minTocHeadings", value: "5", isSynced: true },
- { name: "tocActiveHeadingEnabled", value: "true", isSynced: true },
{ name: "highlightsList", value: '["underline","color","bgColor"]', isSynced: true },
{ name: "checkForUpdates", value: "true", isSynced: true },
{ name: "disableTray", value: "false", isSynced: false },