diff --git a/src/public/app/widgets/toc.js b/src/public/app/widgets/toc.js
index 01fbad1a7..1c0dbc496 100644
--- a/src/public/app/widgets/toc.js
+++ b/src/public/app/widgets/toc.js
@@ -133,7 +133,7 @@ export default class TocWidget extends RightPanelWidget {
// Use jquery to build the table rather than html text, since it makes
// it easier to set the onclick event that will be executed with the
// right captured callback context
- const $toc = $("
");
+ let $toc = $("");
// Note heading 2 is the first level Trilium makes available to the note
let curLevel = 2;
const $ols = [$toc];
@@ -171,12 +171,36 @@ export default class TocWidget extends RightPanelWidget {
headingCount = headingIndex;
}
+ $toc = this.pullLeft($toc);
+
return {
$toc,
headingCount
};
}
+ /**
+ * Reduce indent if a larger headings are not being used: https://github.com/zadam/trilium/issues/4363
+ */
+ pullLeft($toc) {
+ while (true) {
+ const $children = $toc.children();
+
+ if ($children.length !== 1) {
+ break;
+ }
+
+ const $first = $toc.children(":first");
+
+ if ($first[0].tagName !== 'OL') {
+ break;
+ }
+
+ $toc = $first;
+ }
+ return $toc;
+ }
+
async jumpToHeading(headingIndex) {
// A readonly note can change state to "readonly disabled
// temporarily" (ie "edit this note" button) without any