diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 694c441d..ed7f2af3 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -207,7 +207,7 @@ flowchart TD
- **Sidebar** (220-400px, resizable): Top-level filters (All Notes, Changes, Pulse), saved Views, collapsible type-based section groups, and a dedicated folder tree. The folder tree starts with a vault-root row labeled from the opened vault path, shows root-level files when selected, and nests user-created folders plus default vault folders such as `attachments/` and `views/` underneath it; only the dedicated `type/` directory stays hidden because note types already have their own sidebar section. Saved Views persist a top-level YAML `order` field in each view file and use the same ordered-list mental model as Types: pointer users can drag the existing view row, double-click to rename it, or right-click for edit/rename/appearance/delete actions, while keyboard users can use the row context key for the same menu and command-palette move actions for ordering. The folder tree supports inline folder creation and rename, exposes a right-click menu for rename/delete plus filesystem reveal/copy-path actions on mutable folders, and auto-expands ancestor folders when the current selection or rename target is nested. Type sections and folder rows also act as note drop targets: dropping a note on a type updates its `type:` frontmatter, while dropping it on a folder runs the same crash-safe move path as the command palette flow. Each type can have a custom icon, color, sort, and visibility set via its `type: Type` document; new type documents created by Tolaria are written at the vault root.
- **Note List / Pulse View** (220-500px, resizable): When a section group, filter, or saved view is selected, shows filtered notes with snippets, modified dates, status indicators, and per-context note-list controls. When `selection.kind === 'entity'`, the same pane enters **Neighborhood** mode: the source note is pinned at the top as a normal active row, outgoing relationship groups render first, inverse/backlink groups follow, empty groups stay visible with `0`, and duplicates across groups are allowed when multiple relationships are true. Plain click / `Enter` open the focused note without replacing the current Neighborhood, while Cmd/Ctrl-click and Cmd/Ctrl-`Enter` pivot the pane into the clicked note's Neighborhood. Folder-backed lists also show non-Markdown files: previewable image and PDF binaries get file indicators and open in the editor pane, while unsupported binaries remain muted instead of auto-launching an external app. Saved views reuse the same sort and visible-column controls as the built-in lists, and those changes persist back into the view `.yml` definition (`sort`, `listPropertiesDisplay`). When Pulse filter is active, shows `PulseView` — a chronological git activity feed grouped by day.
- **Editor** (flex, fills remaining space): Single note open at a time (no tabs — see ADR-0003). Breadcrumb bar with word count, rich-editor width toggle, and the secondary-overflow Table of Contents action, BlockNote rich text editor with wikilink support, Markdown-compatible inline/display math rendering, first-class Mermaid diagram blocks, markdown-safe formatting controls, and schema-backed fenced code block highlighting via `@blocknote/code-block`. Can toggle to diff view (modified files), raw CodeMirror view, or a wide rich-editor reading surface with preserved side margins; raw CodeMirror remains full-width and unaffected by note width mode. Inline rich-editor images open in a localized shadcn lightbox on double-click while normal single-click BlockNote selection remains untouched, and tiny tracking-style images are ignored. Binary image and PDF files render through `FilePreview` as ordinary vault files using Tauri asset URLs; external-open actions call `open_vault_file_external` so the target is validated against the active vault before the native default app opens it. Unsupported/broken binaries show explicit fallback states and keyboard focus returns to the note list on `Escape`. Decomposed into `Editor` (orchestrator), `EditorContent`, `FilePreview`, `EditorRightPanel`, `TableOfContentsPanel`, `SingleEditorView`, with hooks `useDiffMode`, `useEditorFocus`, and `useEditorSave`, plus the `useRawMode`/`RawEditorView` pair for markdown source editing. Rich BlockNote input and raw CodeMirror input both route typed `->`, `<-`, and `<->` through the shared `src/utils/arrowLigatures.ts` resolver so arrow ligatures stay consistent across mode switches while escaped ASCII sequences remain literal. Navigation history (Cmd+[/]) replaces tabs.
-- **Inspector / Table of Contents / AI Agent** (200-500px or 40px collapsed): `EditorRightPanel` selects between Inspector (frontmatter, relationships, instances, backlinks, git history), Table of Contents (live BlockNote heading outline with collapsible nested headings and cursor navigation), and AI Agent panel (the selected CLI agent with tool execution). The Sparkle icon in the breadcrumb bar toggles AI; the List Bullets icon toggles the TOC and moves into the breadcrumb overflow menu when horizontal space is tight. Per-note `icon` is a suggested Inspector property and the command palette's "Set Note Icon" action opens that field directly. When viewing a Type note, the Inspector shows an **Instances** section listing all notes of that type (sorted by modified_at desc, capped at 50).
+- **Right side panels** (200-500px or hidden): Properties, Table of Contents, and AI Agent are mutually exclusive panels mounted by `EditorRightPanel` and coordinated by `useRightPanelExclusion`. Properties shows frontmatter, relationships, instances, backlinks, and git history; Table of Contents is lazy-mounted only while open, derives a title-rooted H1/H2/H3 hierarchy through a debounced Web Worker per ADR-0109, and reuses folder-tree indentation/guide geometry with heading icons while resolving live BlockNote block IDs at click time for navigation; AI Agent keeps the selected CLI/API target controller mounted for tool execution and chat state. The breadcrumb bar toggles Table of Contents, AI, and Properties actions, and opening one replaces the others. Per-note `icon` is a suggested Properties field and the command palette's "Set Note Icon" action opens that field directly. When viewing a Type note, Properties shows an **Instances** section listing all notes of that type (sorted by modified_at desc, capped at 50).
Panels are separated by `ResizeHandle` components that support drag-to-resize. `useLayoutPanels` clamps the sidebar, note-list, and inspector widths before applying them, keeps the side panes from flex-shrinking below their protected widths, and persists the last chosen widths in installation-local localStorage under `tolaria:layout-panels`.
diff --git a/docs/adr/0109-debounced-worker-derived-editor-indexes.md b/docs/adr/0109-debounced-worker-derived-editor-indexes.md
new file mode 100644
index 00000000..c52504ef
--- /dev/null
+++ b/docs/adr/0109-debounced-worker-derived-editor-indexes.md
@@ -0,0 +1,32 @@
+---
+type: ADR
+id: "0109"
+title: "Debounced worker-derived editor indexes"
+status: active
+date: 2026-05-04
+---
+
+## Context
+
+Right side panels can need derived indexes of the active note, such as the Table of Contents hierarchy. These indexes are useful while editing, but rebuilding them synchronously during note opening or on every keystroke competes with the editor's main-thread work and violates ADR-0105's responsiveness contract.
+
+The Table of Contents also needs live BlockNote block IDs for navigation, while the fastest and most stable source for the outline itself is the active note's Markdown content. Binding the outline rebuild directly to BlockNote document mutations makes typing and note swaps more expensive than necessary.
+
+## Decision
+
+**Derived editor indexes that are not required for the editor surface itself must be lazy, debounced, and built off the main thread when they can be derived from Markdown.** The Table of Contents does not build while its panel is closed; once opened, it uses a Web Worker to build its Markdown-derived H1/H2/H3 tree after a debounce, while live BlockNote block IDs are resolved only at click time for navigation.
+
+## Options considered
+
+- **Lazy debounced Web Worker for Markdown-derived indexes** (chosen): avoids any TOC work while the panel is closed, keeps outline parsing away from typing and note-opening work once opened, cancels stale panel updates, and lets the rendered editor remain the only editor surface. Cons: adds a small worker/client path and a title-only interim state.
+- **Main-thread deferred rebuild with `setTimeout`**: avoids blocking the first render, but still runs on the UI thread and can still rebuild too often during active edits.
+- **Synchronous rebuild from the BlockNote document**: simplest and gives immediate block IDs, but makes every BlockNote document update a potential side-panel rebuild.
+- **Never update the TOC while editing**: safest for typing performance, but stale outlines make the panel misleading for active authoring.
+
+## Consequences
+
+- TOC tree state is driven by note identity plus debounced Markdown content, not by BlockNote document churn.
+- Closing the TOC panel unmounts the panel and cancels pending debounce callbacks; no worker request is scheduled while the panel is closed.
+- The TOC may briefly show only the note title after a note switch or edit burst; the full tree appears when the debounced worker result returns.
+- Navigation remains tied to the live editor: block IDs are resolved from the current BlockNote document at click time and scrolled/focused then.
+- Future derived side-panel indexes should follow the same pattern when they parse or scan note content and are not needed to render the editor itself.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 1578aeb4..f5036ca7 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -162,3 +162,4 @@ proposed → active → superseded
| [0107](0107-markdown-durable-tldraw-whiteboards.md) | Markdown-durable tldraw whiteboards in notes | active |
| [0107](0107-pointer-owned-editor-block-reordering.md) | Pointer-owned editor block reordering | active |
| [0108](0108-sanitized-rendered-markup-and-safe-regex.md) | Sanitized rendered markup and safe user regex | active |
+| [0109](0109-debounced-worker-derived-editor-indexes.md) | Debounced worker-derived editor indexes | active |
diff --git a/src/components/AiPanelChrome.tsx b/src/components/AiPanelChrome.tsx
index 8f75563c..67e8715d 100644
--- a/src/components/AiPanelChrome.tsx
+++ b/src/components/AiPanelChrome.tsx
@@ -200,6 +200,7 @@ export const AiPanelHeader = memo(function AiPanelHeader({
type="button"
variant="ghost"
size="icon-xs"
+ className="h-6 w-6 p-0 [&_svg:not([class*=size-])]:size-4"
onClick={onNewChat}
aria-label={t('ai.panel.newChat')}
title={t('ai.panel.newChat')}
@@ -210,6 +211,7 @@ export const AiPanelHeader = memo(function AiPanelHeader({
type="button"
variant="ghost"
size="icon-xs"
+ className="h-6 w-6 p-0 [&_svg:not([class*=size-])]:size-4"
onClick={onClose}
aria-label={t('ai.panel.close')}
title={t('ai.panel.close')}
diff --git a/src/components/Editor.test.tsx b/src/components/Editor.test.tsx
index 9326ea78..f93ffc37 100644
--- a/src/components/Editor.test.tsx
+++ b/src/components/Editor.test.tsx
@@ -538,9 +538,9 @@ describe('Editor', () => {
expect(screen.getAllByText('Properties').length).toBeGreaterThan(0)
})
- it('renders the table of contents panel from the editor document', () => {
+ it('renders the table of contents panel from the active note content', async () => {
mockEditor.document = [
- { id: 'toc-heading', type: 'heading', content: 'Table Heading', props: { level: 1 }, children: [] },
+ { id: 'toc-heading', type: 'heading', content: [{ type: 'text', text: 'Table Heading' }], props: { level: 2 }, children: [] },
]
render(
@@ -549,13 +549,14 @@ describe('Editor', () => {
tabs={[mockTab]}
activeTabPath={mockEntry.path}
inspectorEntry={mockEntry}
+ inspectorContent={`${mockContent}\n\n## Table Heading`}
/>
)
fireEvent.click(screen.getByRole('button', { name: 'Open table of contents' }))
expect(screen.getByTestId('table-of-contents-panel')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Table Heading' })).toBeInTheDocument()
+ expect(await screen.findByRole('button', { name: 'Table Heading' })).toBeInTheDocument()
})
// Regression: editor content did not appear on first load because BlockNote's
diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx
index e4b988d0..cddaf651 100644
--- a/src/components/Editor.tsx
+++ b/src/components/Editor.tsx
@@ -8,7 +8,6 @@ import { DEFAULT_AI_AGENT, type AiAgentId, type AiAgentReadiness } from '../lib/
import type { AiTarget } from '../lib/aiTargets'
import { translate, type AppLocale } from '../lib/i18n'
import { RUNTIME_STYLE_NONCE } from '../lib/runtimeStyleNonce'
-import { trackEvent } from '../lib/telemetry'
import type { VaultEntry, GitCommit, NoteWidthMode, NoteStatus } from '../types'
import type { NoteListItem } from '../utils/ai-context'
import type { FrontmatterValue } from './Inspector'
@@ -22,6 +21,7 @@ import { EditorContent } from './EditorContent'
import { EditorMemoryProbe } from './EditorMemoryProbe'
import { FilePreview } from './FilePreview'
import { schema } from './editorSchema'
+import { useRightPanelExclusion } from './useRightPanelExclusion'
import type { RawEditorFindRequest } from './RawEditorFindBar'
import {
applyPendingRawExitContent,
@@ -324,6 +324,8 @@ function EditorLayout({
showDiffToggle,
showAIChat,
onToggleAIChat,
+ showTableOfContents,
+ onToggleTableOfContents,
inspectorCollapsed,
onToggleInspector,
onNavigateWikilink,
@@ -389,6 +391,8 @@ function EditorLayout({
showDiffToggle: boolean
showAIChat?: boolean
onToggleAIChat?: () => void
+ showTableOfContents?: boolean
+ onToggleTableOfContents?: () => void
inspectorCollapsed: boolean
onToggleInspector: () => void
onNavigateWikilink: (target: string) => void
@@ -437,27 +441,6 @@ function EditorLayout({
}) {
const activeBinaryTab = activeTab?.entry.fileKind === 'binary' ? activeTab : null
const showEmptyState = tabs.length === 0 && activeTabPath === null && !isVaultLoading
- const [showTableOfContents, setShowTableOfContents] = useState(false)
- const [tableOfContentsRevision, setTableOfContentsRevision] = useState(0)
- const handleEditorChangeWithToc = useCallback(() => {
- handleEditorChange()
- setTableOfContentsRevision((revision) => revision + 1)
- }, [handleEditorChange])
- const handleToggleAIChatExclusive = useCallback(() => {
- if (!showAIChat) setShowTableOfContents(false)
- onToggleAIChat?.()
- }, [onToggleAIChat, showAIChat])
- const handleToggleTableOfContents = useCallback(() => {
- const opening = !showTableOfContents
- if (opening && showAIChat) onToggleAIChat?.()
- setShowTableOfContents(opening)
- trackEvent('table_of_contents_toggled', { open: opening ? 1 : 0 })
- }, [onToggleAIChat, showAIChat, showTableOfContents])
- const handleTableOfContentsHeadingSelected = useCallback(() => {
- trackEvent('table_of_contents_heading_selected')
- }, [])
-
- const visibleTableOfContents = showTableOfContents && !showAIChat
return (