From 3d6fd9dbcf323509b7124444d6d60b8736ce33d0 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 24 Mar 2024 13:42:35 +0100 Subject: [PATCH] Don't fold list nodes FIX: Disable folding for list nodes (since it will shadow the folding on the first list item). See https://discuss.codemirror.net/t/interesting-list-folding-behavior/8021/3 --- src/markdown.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/markdown.ts b/src/markdown.ts index 7d91821..128dfcd 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -10,7 +10,7 @@ const headingProp = new NodeProp() const commonmark = baseParser.configure({ props: [ foldNodeProp.add(type => { - return !type.is("Block") || type.is("Document") || isHeading(type) != null ? undefined + return !type.is("Block") || type.is("Document") || isHeading(type) != null || isList(type) ? undefined : (tree, state) => ({from: state.doc.lineAt(tree.from).to, to: tree.to}) }), headingProp.add(isHeading), @@ -28,6 +28,10 @@ function isHeading(type: NodeType) { return match ? +match[1] : undefined } +function isList(type: NodeType) { + return type.name == "OrderedList" || type.name == "BulletList" +} + function findSectionEnd(headerNode: SyntaxNode, level: number) { let last = headerNode for (;;) {