Debian Codegraph @

frontend/src/codemirror/beancount-indent.ts

raw
1 import { indentService } from "@codemirror/language";
2
3 export const beancountIndent = indentService.of((context, pos) => {
4 const textAfterPos = context.textAfterPos(pos);
5 if (/^\s*\d\d\d\d/.exec(textAfterPos)) {
6 // Lines starting with a date should not be indented.
7 return 0;
8 }
9 const line = context.state.doc.lineAt(pos);
10 if (/^\s+\S+/.exec(line.text) ?? /^\d\d\d\d/.exec(line.text)) {
11 // The previous (or this one?) line was indented.
12 return context.unit;
13 }
14 return 0;
15 });