diff options
Diffstat (limited to 'subprojects/frontend/src/language/indentation.ts')
-rw-r--r-- | subprojects/frontend/src/language/indentation.ts | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/subprojects/frontend/src/language/indentation.ts b/subprojects/frontend/src/language/indentation.ts index 1c38637f..0bd2423c 100644 --- a/subprojects/frontend/src/language/indentation.ts +++ b/subprojects/frontend/src/language/indentation.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { TreeIndentContext } from '@codemirror/language'; | 1 | import type { TreeIndentContext } from '@codemirror/language'; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * Finds the `from` of first non-skipped token, if any, | 4 | * Finds the `from` of first non-skipped token, if any, |
@@ -11,18 +11,16 @@ import { TreeIndentContext } from '@codemirror/language'; | |||
11 | * @returns the alignment or `null` if there is no token after the opening keyword | 11 | * @returns the alignment or `null` if there is no token after the opening keyword |
12 | */ | 12 | */ |
13 | function findAlignmentAfterOpening(context: TreeIndentContext): number | null { | 13 | function findAlignmentAfterOpening(context: TreeIndentContext): number | null { |
14 | const { | 14 | const { node: tree, simulatedBreak } = context; |
15 | node: tree, | ||
16 | simulatedBreak, | ||
17 | } = context; | ||
18 | const openingToken = tree.childAfter(tree.from); | 15 | const openingToken = tree.childAfter(tree.from); |
19 | if (openingToken === null) { | 16 | if (openingToken === null) { |
20 | return null; | 17 | return null; |
21 | } | 18 | } |
22 | const openingLine = context.state.doc.lineAt(openingToken.from); | 19 | const openingLine = context.state.doc.lineAt(openingToken.from); |
23 | const lineEnd = simulatedBreak == null || simulatedBreak <= openingLine.from | 20 | const lineEnd = |
24 | ? openingLine.to | 21 | simulatedBreak == null || simulatedBreak <= openingLine.from |
25 | : Math.min(openingLine.to, simulatedBreak); | 22 | ? openingLine.to |
23 | : Math.min(openingLine.to, simulatedBreak); | ||
26 | const cursor = openingToken.cursor(); | 24 | const cursor = openingToken.cursor(); |
27 | while (cursor.next() && cursor.from < lineEnd) { | 25 | while (cursor.next() && cursor.from < lineEnd) { |
28 | if (!cursor.type.isSkipped) { | 26 | if (!cursor.type.isSkipped) { |
@@ -58,7 +56,10 @@ function findAlignmentAfterOpening(context: TreeIndentContext): number | null { | |||
58 | * @param units the number of units to indent | 56 | * @param units the number of units to indent |
59 | * @returns the desired indentation level | 57 | * @returns the desired indentation level |
60 | */ | 58 | */ |
61 | function indentDeclarationStrategy(context: TreeIndentContext, units: number): number { | 59 | function indentDeclarationStrategy( |
60 | context: TreeIndentContext, | ||
61 | units: number, | ||
62 | ): number { | ||
62 | const alignment = findAlignmentAfterOpening(context); | 63 | const alignment = findAlignmentAfterOpening(context); |
63 | if (alignment !== null) { | 64 | if (alignment !== null) { |
64 | return context.column(alignment); | 65 | return context.column(alignment); |