Indentation and folding without a language

Hi Marijn,

I’d like to enable folding and auto indentation (on enter, based on previous line) for plain text. I’ve tried, and it seems /next’s /fold plugin (and /input/indent) don’t support this?

Is creating a custom language to enable these features the best/only way, or is there something else/better/simpler I could do?

Thank you in advance for your time, and everything you’re doing.

You can wire in whatever logic you want through the indentService and foldService facets, which aren’t dependent on syntax trees.

In case others need this: here is an example of a plain text extension to indent the same amount as the previous line:

import {indentService} from "@codemirror/language"


const indentPlainTextExtension = indentService.of((context, pos) => {
  const previousLine = context.lineAt(pos, -1)
  return previousLine.text.match(/^(\s)*/)[0].length

This extension would then be added to the list of extensions in your EditorState.create(...) call.

1 Like