Skip to content

Commit c06bef3

Browse files
committed
Add foldService so fold gutter always shows on CREATE TABLE lines
Without a foldService, the fold gutter only shows indicators for language-detected folds. The custom createTableFoldService scans for CREATE TABLE lines and declares them foldable, so the ▾/▸ toggle is always visible — not just when programmatically folded.
1 parent 58173fc commit c06bef3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

dashboard/src/components/sandbox/synthesis-output.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
codeFolding,
55
foldEffect,
66
foldGutter,
7+
foldService,
78
} from "@codemirror/language"
89
import { Compartment, EditorState } from "@codemirror/state"
910
import { EditorView, lineNumbers } from "@codemirror/view"
@@ -47,6 +48,27 @@ function getActiveTheme() {
4748
: tokyoNightCmTheme
4849
}
4950

51+
/**
52+
* Fold service that tells CM6 where CREATE TABLE folds are possible.
53+
* This ensures the fold gutter always shows ▾/▸ on CREATE TABLE lines,
54+
* even after the user unfolds them.
55+
*/
56+
const createTableFoldService = foldService.of((state, lineStart) => {
57+
const line = state.doc.lineAt(lineStart)
58+
const text = line.text.trimStart()
59+
if (!text.startsWith("CREATE TABLE")) return null
60+
61+
// Find the end of the statement (the line ending with ;)
62+
let endLine = line
63+
for (let n = line.number + 1; n <= state.doc.lines; n++) {
64+
endLine = state.doc.line(n)
65+
if (endLine.text.trimEnd().endsWith(";")) break
66+
}
67+
68+
// Fold from end of first line to end of last line
69+
return { from: line.to, to: endLine.to }
70+
})
71+
5072
/**
5173
* Compute fold ranges for CREATE TABLE statements.
5274
* Keeps the first line (CREATE TABLE `name` (...) visible and folds the body
@@ -115,6 +137,7 @@ function CodeViewer({
115137
bracketMatching(),
116138
javascript(),
117139
codeFolding({ placeholderText: "…" }),
140+
createTableFoldService,
118141
foldGutter({
119142
openText: "▾",
120143
closedText: "▸",

0 commit comments

Comments
 (0)