@@ -28,6 +28,14 @@ indentAfterEnter := async (content: string): Promise<number> =>
2828 newLineIndex := content.split('\n').length
2929 indentOf doc.lineAt(newLineIndex).text
3030
31+ // Open a doc, type text at end, and return the line that follows the original
32+ // content. Useful for decrease-indent cases that fire while typing the line.
33+ lineAfterTyping := async (content: string, text: string): Promise<string> =>
34+ { doc } := await openCivetAtEnd content
35+ await vscode.commands.executeCommand 'type', { text }
36+ newLineIndex := content.split('\n').length
37+ doc.lineAt(newLineIndex).text
38+
3139suite 'Auto-indent on Enter (issue #170)', =>
3240 test 'indents body after function declaration', async =>
3341 indent := await indentAfterEnter 'function foo()'
@@ -68,3 +76,11 @@ suite 'Auto-indent on Enter (issue #170)', =>
6876 test 'does NOT indent after an inline-then conditional', async =>
6977 indent := await indentAfterEnter 'if cond then x else y'
7078 assert indent is 0, `expected no indent after inline-then, got ${indent}`
79+
80+ test 'does NOT increase indent after a keyword object key', async =>
81+ indent := await indentAfterEnter 'qwe :=\n asd: 1\n class: 2'
82+ assert indent is 4, `expected object-key indent to stay at 4, got ${indent}`
83+
84+ test 'does NOT decrease indent while typing a keyword object key', async =>
85+ line := await lineAfterTyping 'qwe :=\n asd: 1', '\nelse: 2'
86+ assert line is ' else: 2', `expected object-key line to stay indented, got ${JSON.stringify line}`
0 commit comments