Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/editor/foldableHeadings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
foldGutter,
codeFolding,
syntaxTree,
ensureSyntaxTree,
} from '@codemirror/language'
import type { EditorState } from '@codemirror/state'
import type { Tree } from '@lezer/common'
Expand Down Expand Up @@ -45,10 +44,11 @@ interface HeadingInfo {
const headingCache = new WeakMap<Tree, HeadingInfo[]>()

function resolveTree(state: EditorState): Tree {
// Force a full parse so folding works for the whole document (and in headless
// test states with no view driving incremental parsing). Falls back to the
// partial tree if the parse times out on a very large doc.
return ensureSyntaxTree(state, state.doc.length, 5000) ?? syntaxTree(state)
// Use the non-blocking parsed tree (same as the other live-preview
// extensions). The fold gutter only queries visible lines, so a forced
// full-document parse on every per-note editor remount is unnecessary and
// caused a ~1s stall on each note switch.
return syntaxTree(state)
}

function collectHeadings(state: EditorState): HeadingInfo[] {
Expand Down
Loading