Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit a94cdcb

Browse files
committed
Add folding for JSX elements and tags
FIX: Support code folding of JSX elements and tags. Closes #16
1 parent 78a8521 commit a94cdcb

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/javascript.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ export const javascriptLanguage = LRLanguage.define({
4242
}),
4343
foldNodeProp.add({
4444
"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType": foldInside,
45-
BlockComment(tree) { return {from: tree.from + 2, to: tree.to - 2} }
45+
BlockComment(tree) { return {from: tree.from + 2, to: tree.to - 2} },
46+
JSXElement(tree) {
47+
let open = tree.firstChild
48+
if (!open || open.name == "JSXSelfClosingTag") return null
49+
let close = tree.lastChild!
50+
return {from: open.to, to: close.type.isError ? tree.to : close.from}
51+
},
52+
"JSXSelfClosingTag JSXOpenTag"(tree) {
53+
let name = tree.firstChild?.nextSibling, close = tree.lastChild!
54+
if (!name || name.type.isError) return null
55+
return {from: name.to, to: close.type.isError ? tree.to : close.from}
56+
}
4657
})
4758
]
4859
}),
@@ -151,5 +162,5 @@ export const autoCloseTags = EditorView.inputHandler.of((view, from, to, text, d
151162
state.update(closeTags, {userEvent: "input.complete", scrollIntoView: true})
152163
])
153164
return true
154-
});
165+
})
155166

0 commit comments

Comments
 (0)