Skip to content

feat(editor): auto-close left sidebar when TOC is empty#651

Merged
backnotprop merged 2 commits intomainfrom
feat/empty-toc-collapse-side
May 2, 2026
Merged

feat(editor): auto-close left sidebar when TOC is empty#651
backnotprop merged 2 commits intomainfrom
feat/empty-toc-collapse-side

Conversation

@backnotprop
Copy link
Copy Markdown
Owner

Summary

  • When a document has no level 1-3 headings (common in annotate / annotate-last sessions and structureless plans), keep the left sidebar closed regardless of the "Auto-open Sidebar" preference.
  • The collapsed flag strip remains available so users can still open it manually; manual re-open isn't overridden until the document changes again (e.g. picking a new file in annotate-folder).
  • Mode overrides untouched: archive still forces the Archive tab open, annotate-folder still forces Files.

Implementation

In packages/editor/App.tsx:

  • Derive hasTocEntries from blocks using the same level <= 3 rule as buildTocHierarchy.
  • Gate the existing tocEnabled sync effect: only sidebar.open('toc') when hasTocEntries is true. Closing on toggle-off is preserved.
  • Add a one-shot effect keyed on [blocks, hasTocEntries] that closes the sidebar when blocks parse with no TOC entries and the active tab is TOC. Intentionally does not depend on sidebar state, so a manual re-open sticks until the document changes.

Test plan

  • Plan with headings: sidebar opens to TOC per tocEnabled (unchanged).
  • Plan with no headings: sidebar stays closed; clicking the TOC flag still opens it.
  • annotate / annotate-last on a heading-less doc: sidebar stays closed.
  • annotate-folder: switching between files with/without headings keeps Files tab open; switching to TOC tab on a heading-less file closes the sidebar.
  • archive mode: Archive tab still force-opens.
  • Toggle "Auto-open Sidebar" in Settings on a heading-less doc: no flicker, sidebar stays closed.

When the parsed document has no level 1-3 headings (common for annotate
and annotate-last sessions), keep the sidebar closed regardless of the
"Auto-open Sidebar" preference. The collapsed flag strip stays
available so users can still open it manually; manual re-open is not
overridden until the document changes again.
Adding hasTocEntries to the tocEnabled sync effect's dep array while
the const itself was declared 300+ lines later threw a TDZ error at
render ("Cannot access 'Pe' before initialization" in the minified
bundle). Move the useMemo above the effects so dep-array evaluation
sees an initialized binding.
@backnotprop backnotprop merged commit 2b144cb into main May 2, 2026
7 checks passed
@backnotprop backnotprop deleted the feat/empty-toc-collapse-side branch May 2, 2026 19:32
HeikoAtGitHub pushed a commit to HeikoAtGitHub/plannotator that referenced this pull request May 3, 2026
)

* feat(editor): auto-close left sidebar when TOC is empty

When the parsed document has no level 1-3 headings (common for annotate
and annotate-last sessions), keep the sidebar closed regardless of the
"Auto-open Sidebar" preference. The collapsed flag strip stays
available so users can still open it manually; manual re-open is not
overridden until the document changes again.

* fix(editor): hoist hasTocEntries above the effects that read it

Adding hasTocEntries to the tocEnabled sync effect's dep array while
the const itself was declared 300+ lines later threw a TDZ error at
render ("Cannot access 'Pe' before initialization" in the minified
bundle). Move the useMemo above the effects so dep-array evaluation
sees an initialized binding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant