Skip to content

Add opt-in code and Markdown folding in the gutter - #467

Open
simonbs wants to merge 9 commits into
mainfrom
codex/code-folding
Open

simonbs wants to merge 9 commits into
mainfrom
codex/code-folding

Conversation

@simonbs

@simonbs simonbs commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Add folding for code blocks and Markdown sections, with controls in the gutter. Folded rows fade in place while the following rows slide up or down to make room. Each gutter control uses a single SF Symbol chevron that rotates with the transition.

Folding is disabled by default. Enable it on a text view:

textView.isCodeFoldingEnabled = true

Use a language with folding queries from TreeSitterLanguages #39. Tap a gutter chevron to collapse or expand a region. Markdown supports ATX and Setext sections, fenced code, and nested folds. Collapsing preserves the document and its logical line numbers, and nested folds retain their collapsed state when a parent reopens. Gutter controls also work when line numbers are hidden.

The Example app includes a Code Folding setting and a Folding Examples submenu with JavaScript and Markdown samples.

Screenshots

Expanded Collapsed section and function
Markdown and injected JavaScript expanded Markdown section and JavaScript function collapsed in the gutter

Animation

runestone-folding-body-fade-tail-slide.mp4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant